| 36 | | p = Popen(arglist, stdout=output, stderr=STDOUT, env=env) |
|---|
| 37 | | except Exception, e: |
|---|
| 38 | | return 1, e |
|---|
| 39 | | |
|---|
| 40 | | # Wait only max_timeout seconds. |
|---|
| 41 | | if max_timeout: |
|---|
| 42 | | start = time.time() |
|---|
| 43 | | while p.poll() is None: |
|---|
| 44 | | time.sleep(0.1) |
|---|
| 45 | | if time.time() - start > max_timeout: |
|---|
| 46 | | os.kill(p.pid, signal.SIGINT) |
|---|
| 47 | | p.wait() |
|---|
| 48 | | return 1, "Time exceeded" |
|---|
| 49 | | |
|---|
| 50 | | p.wait() |
|---|
| 51 | | output.seek(0) |
|---|
| 52 | | |
|---|
| 53 | | output_content = output.read() |
|---|
| 54 | | output.close() |
|---|
| 55 | | os.unlink(output_name) |
|---|
| 56 | | |
|---|
| 57 | | return p.returncode, output_content |
|---|
| | 36 | try: |
|---|
| | 37 | p = Popen(arglist, stdout=output, stderr=STDOUT, env=env) |
|---|
| | 38 | |
|---|
| | 39 | # Wait only max_timeout seconds. |
|---|
| | 40 | if max_timeout: |
|---|
| | 41 | start = time.time() |
|---|
| | 42 | while p.poll() is None: |
|---|
| | 43 | time.sleep(0.1) |
|---|
| | 44 | if time.time() - start > max_timeout: |
|---|
| | 45 | os.kill(p.pid, signal.SIGINT) |
|---|
| | 46 | p.wait() |
|---|
| | 47 | return 1, "Time exceeded" |
|---|
| | 48 | |
|---|
| | 49 | p.wait() |
|---|
| | 50 | output.seek(0) |
|---|
| | 51 | |
|---|
| | 52 | output_content = output.read() |
|---|
| | 53 | |
|---|
| | 54 | return p.returncode, output_content |
|---|
| | 55 | except Exception, e: |
|---|
| | 56 | return 1, e |
|---|
| | 57 | finally: |
|---|
| | 58 | output.close() |
|---|
| | 59 | os.unlink(output_name) |
|---|