diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-05-08 17:14:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 17:14:14 (GMT) |
commit | 4270b7927de2260f5f1442bb90f788e9ad25ce9c (patch) | |
tree | edf7487e853bbef369d1eb8f0815aaa281b169b4 /Lib/test/test_concurrent_futures.py | |
parent | 5917e71017af916e4e03953794ec85f0381d8625 (diff) | |
download | cpython-4270b7927de2260f5f1442bb90f788e9ad25ce9c.zip cpython-4270b7927de2260f5f1442bb90f788e9ad25ce9c.tar.gz cpython-4270b7927de2260f5f1442bb90f788e9ad25ce9c.tar.bz2 |
gh-90622: Do not spawn ProcessPool workers on demand via fork method. (GH-91598) (#92495)
Do not spawn ProcessPool workers on demand when they spawn via fork.
This avoids potential deadlocks in the child processes due to forking from
a multithreaded process.
(cherry picked from commit ebb37fc3fdcb03db4e206db017eeef7aaffbae84)
Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/test_concurrent_futures.py')
-rw-r--r-- | Lib/test/test_concurrent_futures.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 4363e90..6f3b460 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -497,10 +497,16 @@ class ProcessPoolShutdownTest(ExecutorShutdownTest): lock.acquire() mp_context = self.get_context() + if mp_context.get_start_method(allow_none=False) == "fork": + # fork pre-spawns, not on demand. + expected_num_processes = self.worker_count + else: + expected_num_processes = 3 + sem = mp_context.Semaphore(0) for _ in range(3): self.executor.submit(acquire_lock, sem) - self.assertEqual(len(self.executor._processes), 3) + self.assertEqual(len(self.executor._processes), expected_num_processes) for _ in range(3): sem.release() processes = self.executor._processes @@ -1021,6 +1027,8 @@ class ProcessPoolExecutorTest(ExecutorTest): def test_idle_process_reuse_one(self): executor = self.executor assert executor._max_workers >= 4 + if self.get_context().get_start_method(allow_none=False) == "fork": + raise unittest.SkipTest("Incompatible with the fork start method.") executor.submit(mul, 21, 2).result() executor.submit(mul, 6, 7).result() executor.submit(mul, 3, 14).result() @@ -1029,6 +1037,8 @@ class ProcessPoolExecutorTest(ExecutorTest): def test_idle_process_reuse_multiple(self): executor = self.executor assert executor._max_workers <= 5 + if self.get_context().get_start_method(allow_none=False) == "fork": + raise unittest.SkipTest("Incompatible with the fork start method.") executor.submit(mul, 12, 7).result() executor.submit(mul, 33, 25) executor.submit(mul, 25, 26).result() |