~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tools/jsrun.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import time
 
2
from subprocess import Popen, PIPE, STDOUT
 
3
 
 
4
def timeout_run(proc, timeout, note='unnamed process', full_output=False):
 
5
  start = time.time()
 
6
  if timeout is not None:
 
7
    while time.time() - start < timeout and proc.poll() is None:
 
8
      time.sleep(0.1)
 
9
    if proc.poll() is None:
 
10
      proc.kill() # XXX bug: killing emscripten.py does not kill it's child process!
 
11
      raise Exception("Timed out: " + note)
 
12
  out = proc.communicate()
 
13
  return '\n'.join(out) if full_output else out[0]
 
14
 
 
15
def run_js(filename, engine=None, args=[], check_timeout=False, stdout=PIPE, stderr=None, cwd=None, full_output=False):
 
16
  if type(engine) is not list:
 
17
    engine = [engine]
 
18
  command = engine + [filename] + (['--'] if 'd8' in engine[0] else []) + args
 
19
  return timeout_run(
 
20
    Popen(
 
21
      command,
 
22
      stdout=stdout,
 
23
      stderr=stderr,
 
24
      cwd=cwd),
 
25
    15*60 if check_timeout else None,
 
26
    'Execution',
 
27
    full_output=full_output)