Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion checkbox-support/checkbox_support/helpers/timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,14 @@ def _f(*args, **kwargs):

process = Process(target=_f, args=args, kwargs=kwargs)
process.start()
process.join(timeout_s)
try:
process.join(timeout_s)
except BaseException:
# If an exception is raised in the main process, we will kill the
# process tree
kill_tree(process.pid)
# Re-raise so the parent can exit
raise

if process.is_alive():
# this tries to kill the whole process tree, not just the child.
Expand Down
6 changes: 6 additions & 0 deletions checkbox-support/checkbox_support/tests/test_timeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ def test_function_exception_propagation(self):
with self.assertRaises(ValueError):
run_with_timeout(some_exception_raiser, 1)

@patch("checkbox_support.helpers.timeout.Process.join")
def test_function_exception_propagation_in_process(self, mock_join):
mock_join.side_effect = KeyboardInterrupt()
with self.assertRaises(BaseException):
run_with_timeout(heavy_function, 1)

def test_function_systemexit_propagation(self):
with self.assertRaises(SystemExit):
system_exit_raiser()
Expand Down
Loading