Skip to content

Commit

Permalink
Make test_parallel_with_interactively_defined_functions_default_backe…
Browse files Browse the repository at this point in the history
…nd timeout more informatively on macos CI (#1332)
  • Loading branch information
ogrisel authored Sep 14, 2022
1 parent 54f4d21 commit bdf47e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 9 additions & 3 deletions joblib/test/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ def test_parallel_with_unpicklable_functions_in_args(

INTERACTIVE_DEFINED_FUNCTION_AND_CLASS_SCRIPT_CONTENT = """\
import sys
import faulthandler
# Make sure that joblib is importable in the subprocess launching this
# script. This is needed in case we run the tests from the joblib root
# folder without having installed joblib
Expand All @@ -1056,6 +1057,9 @@ def square(x, ignored=None, ignored2=None):
# Here, we do not need the `if __name__ == "__main__":` safeguard when
# using the default `loky` backend (even on Windows).
# To make debugging easier
faulthandler.dump_traceback_later(30, exit=True)
# The following baroque function call is meant to check that joblib
# introspection rightfully uses cloudpickle instead of the (faster) pickle
# module of the standard library when necessary. In particular cloudpickle is
Expand All @@ -1078,9 +1082,11 @@ def test_parallel_with_interactively_defined_functions_default_backend(tmpdir):
# filesystem script.
script = tmpdir.join('joblib_interactively_defined_function.py')
script.write(INTERACTIVE_DEFINED_FUNCTION_AND_CLASS_SCRIPT_CONTENT)
check_subprocess_call([sys.executable, script.strpath],
stdout_regex=r'\[0, 1, 4, 9, 16\]',
timeout=5)
check_subprocess_call(
[sys.executable, script.strpath],
stdout_regex=r'\[0, 1, 4, 9, 16\]',
timeout=None, # rely on faulthandler to kill the process
)


INTERACTIVELY_DEFINED_SUBCLASS_WITH_METHOD_SCRIPT_CONTENT = """\
Expand Down
8 changes: 5 additions & 3 deletions joblib/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ def kill_process():
warnings.warn("Timeout running {}".format(cmd))
proc.kill()

timer = threading.Timer(timeout, kill_process)
try:
timer.start()
if timeout is not None:
timer = threading.Timer(timeout, kill_process)
timer.start()
stdout, stderr = proc.communicate()
stdout, stderr = stdout.decode(), stderr.decode()
if proc.returncode != 0:
Expand All @@ -74,4 +75,5 @@ def kill_process():
stderr_regex, stderr))

finally:
timer.cancel()
if timeout is not None:
timer.cancel()

0 comments on commit bdf47e9

Please sign in to comment.