summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--framework/process.py27
1 files changed, 9 insertions, 18 deletions
diff --git a/framework/process.py b/framework/process.py
index 1986f50..78b3437 100644
--- a/framework/process.py
+++ b/framework/process.py
@@ -21,10 +21,10 @@
# IN THE SOFTWARE.
#
import os
-import subprocess
import sys
import time
-from threading import Thread, Timer
+from subprocess import Popen, PIPE, TimeoutExpired
+from threading import Thread
__all__ = ['runProgram']
@@ -44,19 +44,10 @@ def runProgram(cmd, timeout, env = None):
else:
fullEnv = os.environ
- proc = subprocess.Popen(cmd,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env=fullEnv,
- universal_newlines=True)
- timeoutExpired = [] # A bool would make sense, but it needs to be mutable.
- def timerCallback():
- timeoutExpired.append(True)
- proc.kill()
- t = Timer(timeout, timerCallback)
- t.start()
-
- out, err = proc.communicate()
- t.cancel()
-
- return (out, err, proc.returncode, not timeoutExpired)
+ try:
+ proc = Popen(cmd, stdout=PIPE, stderr=PIPE, env=fullEnv,
+ universal_newlines=True)
+ out, err = proc.communicate(timeout=timeout)
+ return (out, err, proc.returncode, True)
+ except TimeoutExpired:
+ return (out, err, proc.returncode, False)