diff options
author | Charles-François Natali <cf.natali@gmail.com> | 2016-02-10 22:58:18 +0000 |
---|---|---|
committer | Charles-François Natali <cf.natali@gmail.com> | 2016-02-10 22:58:18 +0000 |
commit | 78f55ffc63ba637ffa4a07ca869f451e680b002a (patch) | |
tree | 989eba7361182ad95629aba10c19fc81c3720037 /Lib/test/_test_multiprocessing.py | |
parent | eaf8ebc139b22efa3ecb844f320908aee80c77bd (diff) | |
download | cpython-78f55ffc63ba637ffa4a07ca869f451e680b002a.tar.gz cpython-78f55ffc63ba637ffa4a07ca869f451e680b002a.zip |
Issue #23992: multiprocessing: make MapResult not fail-fast upon exception.
Diffstat (limited to 'Lib/test/_test_multiprocessing.py')
-rw-r--r-- | Lib/test/_test_multiprocessing.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/_test_multiprocessing.py b/Lib/test/_test_multiprocessing.py index e9120abe5d9..a59d2ba6692 100644 --- a/Lib/test/_test_multiprocessing.py +++ b/Lib/test/_test_multiprocessing.py @@ -1660,6 +1660,10 @@ def sqr(x, wait=0.0): def mul(x, y): return x*y +def raise_large_valuerror(wait): + time.sleep(wait) + raise ValueError("x" * 1024**2) + class SayWhenError(ValueError): pass def exception_throwing_generator(total, when): @@ -1895,6 +1899,26 @@ class _TestPool(BaseTestCase): with self.assertRaises(RuntimeError): p.apply(self._test_wrapped_exception) + def test_map_no_failfast(self): + # Issue #23992: the fail-fast behaviour when an exception is raised + # during map() would make Pool.join() deadlock, because a worker + # process would fill the result queue (after the result handler thread + # terminated, hence not draining it anymore). + + t_start = time.time() + + with self.assertRaises(ValueError): + with self.Pool(2) as p: + try: + p.map(raise_large_valuerror, [0, 1]) + finally: + time.sleep(0.5) + p.close() + p.join() + + # check that we indeed waited for all jobs + self.assertGreater(time.time() - t_start, 0.9) + def raising(): raise KeyError("key") |