Skip to content

Commit

Permalink
Obtain process output on timeout
Browse files Browse the repository at this point in the history
This allows us to use the result of runs that timed out.

Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Jul 5, 2017
1 parent 29b1c89 commit ab51f2e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions rebench/subprocess_with_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,22 @@ def run(args, cwd = None, shell = False, kill_tree = True, timeout = -1,

if timeout != -1 and thread.is_alive():
assert thread.pid is not None
return kill_process(thread.pid, kill_tree)
return kill_process(thread.pid, kill_tree, thread)

return thread.returncode, thread.stdout_result, thread.stderr_result


def kill_process(pid, recursively):
def kill_process(pid, recursively, thread):
pids = [pid]
if recursively:
pids.extend(get_process_children(pid))

for p in pids:
kill(p, SIGKILL)

return -9, '', ''
thread.join()

return -9, thread.stdout_result, thread.stderr_result


def get_process_children(pid):
Expand Down
4 changes: 2 additions & 2 deletions rebench/tests/subprocess_timeout_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_exec_with_timeout(self):

self.assertEqual(-9, return_code)
self.assertEqual("", output)
self.assertEqual("", err)
self.assertEqual(None, err)

def test_exec_with_timeout_python_interpreter(self):
cmdline = "python -c \"while True: pass\""
Expand All @@ -61,7 +61,7 @@ def test_exec_with_timeout_python_interpreter(self):

self.assertEqual(-9, return_code)
self.assertEqual("", output)
self.assertEqual("", err)
self.assertEqual(None, err)


def test_suite():
Expand Down

0 comments on commit ab51f2e

Please sign in to comment.