diff options
author | Kyle Stanley <aeros167@gmail.com> | 2020-04-19 14:00:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-19 14:00:59 (GMT) |
commit | 1ac6e379297cc1cf8acf6c1b011fccc7b3da2cbe (patch) | |
tree | 89df3b0a4f0a8775039b6d4c3ea7a90624a72f65 /Lib/test/test_concurrent_futures.py | |
parent | c12375aa0b838d34067efa3f1b9a1fbc632d0413 (diff) | |
download | cpython-1ac6e379297cc1cf8acf6c1b011fccc7b3da2cbe.zip cpython-1ac6e379297cc1cf8acf6c1b011fccc7b3da2cbe.tar.gz cpython-1ac6e379297cc1cf8acf6c1b011fccc7b3da2cbe.tar.bz2 |
bpo-39207: Spawn workers on demand in ProcessPoolExecutor (GH-19453)
Roughly based on https://github.com/python/cpython/commit/904e34d4e6b6007986dcc585d5c553ee8ae06f95, but with a few substantial differences.
/cc @pitrou @brianquinlan
Diffstat (limited to 'Lib/test/test_concurrent_futures.py')
-rw-r--r-- | Lib/test/test_concurrent_futures.py | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py index 868415a..a8c5bb6 100644 --- a/Lib/test/test_concurrent_futures.py +++ b/Lib/test/test_concurrent_futures.py @@ -486,10 +486,16 @@ class ProcessPoolShutdownTest(ExecutorShutdownTest): pass def test_processes_terminate(self): - self.executor.submit(mul, 21, 2) - self.executor.submit(mul, 6, 7) - self.executor.submit(mul, 3, 14) - self.assertEqual(len(self.executor._processes), 5) + def acquire_lock(lock): + lock.acquire() + + mp_context = get_context() + sem = mp_context.Semaphore(0) + for _ in range(3): + self.executor.submit(acquire_lock, sem) + self.assertEqual(len(self.executor._processes), 3) + for _ in range(3): + sem.release() processes = self.executor._processes self.executor.shutdown() @@ -964,6 +970,36 @@ class ProcessPoolExecutorTest(ExecutorTest): mgr.shutdown() mgr.join() + def test_saturation(self): + executor = self.executor_type(4) + mp_context = get_context() + sem = mp_context.Semaphore(0) + job_count = 15 * executor._max_workers + try: + for _ in range(job_count): + executor.submit(sem.acquire) + self.assertEqual(len(executor._processes), executor._max_workers) + for _ in range(job_count): + sem.release() + finally: + executor.shutdown() + + def test_idle_process_reuse_one(self): + executor = self.executor_type(4) + executor.submit(mul, 21, 2).result() + executor.submit(mul, 6, 7).result() + executor.submit(mul, 3, 14).result() + self.assertEqual(len(executor._processes), 1) + executor.shutdown() + + def test_idle_process_reuse_multiple(self): + executor = self.executor_type(4) + executor.submit(mul, 12, 7).result() + executor.submit(mul, 33, 25) + executor.submit(mul, 25, 26).result() + executor.submit(mul, 18, 29) + self.assertLessEqual(len(executor._processes), 2) + executor.shutdown() create_executor_tests(ProcessPoolExecutorTest, executor_mixins=(ProcessPoolForkMixin, |