Detect exited threaded mapping workers
This commit is contained in:
parent
681ec1174d
commit
c7ded92201
1 changed files with 30 additions and 0 deletions
23
tests/utilities/test_threaded_map_regressions.py
Normal file
23
tests/utilities/test_threaded_map_regressions.py
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import subprocess
|
||||
import sys
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exception", ["SystemExit", "KeyboardInterrupt"])
|
||||
def test_exited_thread_is_reported(exception: str) -> None:
|
||||
script = f"""
|
||||
from great_ai.utilities import threaded_parallel_map, WorkerException
|
||||
def dead(value):
|
||||
raise {exception}()
|
||||
try:
|
||||
list(threaded_parallel_map(dead, [1], concurrency=1))
|
||||
except WorkerException as error:
|
||||
assert 'exited unexpectedly' in str(error)
|
||||
else:
|
||||
raise AssertionError('Worker exit was ignored')
|
||||
"""
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", script], capture_output=True, text=True, timeout=10
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
Loading…
Reference in a new issue