Permalink
Browse files

Python 2.5 compatibility

  • Loading branch information...
1 parent d9b70c8 commit 29f8dd1ba1e288ab3afd65cf35b6106fb7b9717a Brice Fernandes committed Jun 8, 2012
Showing with 32 additions and 6 deletions.
  1. +4 −1 envoy/__init__.py
  2. +27 −4 envoy/core.py
  3. +1 −1 setup.py
View
@@ -1,3 +1,6 @@
-from .core import *
+
+
+from .core import Command, ConnectedCommand, Response
+from .core import expand_args, run, connect
from .core import __version__
View
@@ -10,6 +10,7 @@
import os
import sys
import shlex
+import signal
import subprocess
import threading
@@ -19,6 +20,28 @@
__author__ = 'Kenneth Reitz'
+def _terminate_process(process):
+ if sys.platform == 'win32':
+ import ctypes
+ PROCESS_TERMINATE = 1
+ handle = ctypes.windll.kernel32.OpenProcess(PROCESS_TERMINATE, False, process.pid)
+ ctypes.windll.kernel32.TerminateProcess(handle, -1)
+ ctypes.windll.kernel32.CloseHandle(handle)
+ else:
+ os.kill(process.pid, signal.SIGTERM)
+
+def _kill_process(process):
+ if sys.platform == 'win32':
+ _terminate_process(process)
+ else:
+ os.kill(process.pid, signal.SIGKILL)
+
+def _is_alive(thread):
+ if hasattr(thread, "is_alive"):
+ return thread.is_alive()
+ else:
+ return thread.isAlive()
+
class Command(object):
def __init__(self, cmd):
self.cmd = cmd
@@ -56,11 +79,11 @@ def target():
thread.start()
thread.join(timeout)
- if thread.is_alive():
- self.process.terminate()
+ if _is_alive(thread) :
+ _terminate_process(self.process)
thread.join(kill_timeout)
- if thread.is_alive():
- self.process.kill()
+ if _is_alive(thread):
+ _kill_process(self.process)
thread.join()
self.returncode = self.process.returncode
return self.out, self.err
View
@@ -35,7 +35,7 @@
'Natural Language :: English',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
- # 'Programming Language :: Python :: 2.5',
+ 'Programming Language :: Python :: 2.5',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.0',

0 comments on commit 29f8dd1

Please sign in to comment.