@@ -486,10 +486,16 @@ def _prime_executor(self):
486486 pass
487487
488488 def test_processes_terminate (self ):
489- self .executor .submit (mul , 21 , 2 )
490- self .executor .submit (mul , 6 , 7 )
491- self .executor .submit (mul , 3 , 14 )
492- self .assertEqual (len (self .executor ._processes ), 5 )
489+ def acquire_lock (lock ):
490+ lock .acquire ()
491+
492+ mp_context = get_context ()
493+ sem = mp_context .Semaphore (0 )
494+ for _ in range (3 ):
495+ self .executor .submit (acquire_lock , sem )
496+ self .assertEqual (len (self .executor ._processes ), 3 )
497+ for _ in range (3 ):
498+ sem .release ()
493499 processes = self .executor ._processes
494500 self .executor .shutdown ()
495501
@@ -964,6 +970,36 @@ def test_ressources_gced_in_workers(self):
964970 mgr .shutdown ()
965971 mgr .join ()
966972
973+ def test_saturation (self ):
974+ executor = self .executor_type (4 )
975+ mp_context = get_context ()
976+ sem = mp_context .Semaphore (0 )
977+ job_count = 15 * executor ._max_workers
978+ try :
979+ for _ in range (job_count ):
980+ executor .submit (sem .acquire )
981+ self .assertEqual (len (executor ._processes ), executor ._max_workers )
982+ for _ in range (job_count ):
983+ sem .release ()
984+ finally :
985+ executor .shutdown ()
986+
987+ def test_idle_process_reuse_one (self ):
988+ executor = self .executor_type (4 )
989+ executor .submit (mul , 21 , 2 ).result ()
990+ executor .submit (mul , 6 , 7 ).result ()
991+ executor .submit (mul , 3 , 14 ).result ()
992+ self .assertEqual (len (executor ._processes ), 1 )
993+ executor .shutdown ()
994+
995+ def test_idle_process_reuse_multiple (self ):
996+ executor = self .executor_type (4 )
997+ executor .submit (mul , 12 , 7 ).result ()
998+ executor .submit (mul , 33 , 25 )
999+ executor .submit (mul , 25 , 26 ).result ()
1000+ executor .submit (mul , 18 , 29 )
1001+ self .assertLessEqual (len (executor ._processes ), 2 )
1002+ executor .shutdown ()
9671003
9681004create_executor_tests (ProcessPoolExecutorTest ,
9691005 executor_mixins = (ProcessPoolForkMixin ,
0 commit comments