~ubuntu-branches/ubuntu/trusty/emscripten/trusty-proposed

« back to all changes in this revision

Viewing changes to tools/jsrun.py

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2014-01-19 14:12:40 UTC
  • mfrom: (1.2.4)
  • Revision ID: package-import@ubuntu.com-20140119141240-jg1l42cc158j59tn
Tags: 1.9.0~20140119~7dc8c2f-1
* New snapshot release (Closes: #733714)
* Provide sources for javascript and flash. Done in orig-tar.sh
  Available in third_party/websockify/include/web-socket-js/src/
  (Closes: #735903)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import time
 
1
import time, os, sys, logging
2
2
from subprocess import Popen, PIPE, STDOUT
3
3
 
4
 
def timeout_run(proc, timeout, note='unnamed process', full_output=False):
 
4
TRACK_PROCESS_SPAWNS = True if (os.getenv('EM_BUILD_VERBOSE') and int(os.getenv('EM_BUILD_VERBOSE')) >= 3) else False
 
5
 
 
6
def timeout_run(proc, timeout=None, note='unnamed process', full_output=False):
5
7
  start = time.time()
6
8
  if timeout is not None:
7
9
    while time.time() - start < timeout and proc.poll() is None:
11
13
      raise Exception("Timed out: " + note)
12
14
  out = proc.communicate()
13
15
  out = map(lambda o: '' if o is None else o, out)
 
16
  if TRACK_PROCESS_SPAWNS:
 
17
    logging.info('Process ' + str(proc.pid) + ' finished after ' + str(time.time() - start) + ' seconds.')
14
18
  return '\n'.join(out) if full_output else out[0]
15
19
 
16
20
def run_js(filename, engine=None, args=[], check_timeout=False, stdin=None, stdout=PIPE, stderr=None, cwd=None, full_output=False):
17
21
  if type(engine) is not list:
18
22
    engine = [engine]
19
23
  command = engine + [filename] + (['--'] if 'd8' in engine[0] or 'jsc' in engine[0] else []) + args
20
 
  return timeout_run(
21
 
    Popen(
 
24
  proc = Popen(
22
25
      command,
23
26
      stdin=stdin,
24
27
      stdout=stdout,
25
28
      stderr=stderr,
26
 
      cwd=cwd),
27
 
    15*60 if check_timeout else None,
 
29
      cwd=cwd)
 
30
  timeout = 15*60 if check_timeout else None
 
31
  if TRACK_PROCESS_SPAWNS:
 
32
    logging.info('Blocking on process ' + str(proc.pid) + ': ' + str(command) + (' for ' + str(timeout) + ' seconds' if timeout else ' until it finishes.'))
 
33
  return timeout_run(
 
34
    proc, 
 
35
    timeout,
28
36
    'Execution',
29
37
    full_output=full_output)