diff options
author | Chad Austin <chad@imvu.com> | 2013-01-30 16:39:40 -0800 |
---|---|---|
committer | Chad Austin <chad@imvu.com> | 2013-03-04 19:14:38 -0800 |
commit | d0423ad1cc42fd552472c94aaf26410e7a7b73b8 (patch) | |
tree | b24a6371c25b8568306fd1e939ad3855bb4b8a66 /tools/jsrun.py | |
parent | 024cc62dd2e46c1e5dcbed79ff720d3dc0f16fe5 (diff) |
Move run_js into jsrun.py (work towards breaking emscripten.py's dependency on shared, which requires .emscripten at import time)
Diffstat (limited to 'tools/jsrun.py')
-rw-r--r-- | tools/jsrun.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/jsrun.py b/tools/jsrun.py new file mode 100644 index 00000000..27c55350 --- /dev/null +++ b/tools/jsrun.py @@ -0,0 +1,27 @@ +import time +from subprocess import Popen, PIPE, STDOUT + +def timeout_run(proc, timeout, note='unnamed process', full_output=False): + start = time.time() + if timeout is not None: + while time.time() - start < timeout and proc.poll() is None: + time.sleep(0.1) + if proc.poll() is None: + proc.kill() # XXX bug: killing emscripten.py does not kill it's child process! + raise Exception("Timed out: " + note) + out = proc.communicate() + return '\n'.join(out) if full_output else out[0] + +def run_js(filename, engine=None, args=[], check_timeout=False, stdout=PIPE, stderr=None, cwd=None, full_output=False): + if type(engine) is not list: + engine = [engine] + command = engine + [filename] + (['--'] if 'd8' in engine[0] else []) + args + return timeout_run( + Popen( + command, + stdout=stdout, + stderr=stderr, + cwd=cwd), + 15*60 if check_timeout else None, + 'Execution', + full_output=full_output) |