@@ -4376,18 +4376,13 @@ def test_shared_memory_cleaned_after_process_termination(self):
43764376 p .terminate ()
43774377 p .wait ()
43784378
4379- deadline = time .monotonic () + support .LONG_TIMEOUT
4380- t = 0.1
4381- while time .monotonic () < deadline :
4382- time .sleep (t )
4383- t = min (t * 2 , 5 )
4379+ err_msg = ("A SharedMemory segment was leaked after "
4380+ "a process was abruptly terminated" )
4381+ for _ in support .sleeping_retry (support .LONG_TIMEOUT , err_msg ):
43844382 try :
43854383 smm = shared_memory .SharedMemory (name , create = False )
43864384 except FileNotFoundError :
43874385 break
4388- else :
4389- raise AssertionError ("A SharedMemory segment was leaked after"
4390- " a process was abruptly terminated." )
43914386
43924387 if os .name == 'posix' :
43934388 # Without this line it was raising warnings like:
@@ -5458,20 +5453,18 @@ def create_and_register_resource(rtype):
54585453 p .terminate ()
54595454 p .wait ()
54605455
5461- deadline = time .monotonic () + support .LONG_TIMEOUT
5462- while time .monotonic () < deadline :
5463- time .sleep (.5 )
5456+ err_msg = (f"A { rtype } resource was leaked after a process was "
5457+ f"abruptly terminated" )
5458+ for _ in support .sleeping_retry (support .SHORT_TIMEOUT ,
5459+ err_msg ):
54645460 try :
54655461 _resource_unlink (name2 , rtype )
54665462 except OSError as e :
54675463 # docs say it should be ENOENT, but OSX seems to give
54685464 # EINVAL
54695465 self .assertIn (e .errno , (errno .ENOENT , errno .EINVAL ))
54705466 break
5471- else :
5472- raise AssertionError (
5473- f"A { rtype } resource was leaked after a process was "
5474- f"abruptly terminated." )
5467+
54755468 err = p .stderr .read ().decode ('utf-8' )
54765469 p .stderr .close ()
54775470 expected = ('resource_tracker: There appear to be 2 leaked {} '
@@ -5707,18 +5700,17 @@ def wait_proc_exit(self):
57075700 # but this can take a bit on slow machines, so wait a few seconds
57085701 # if there are other children too (see #17395).
57095702 join_process (self .proc )
5703+
57105704 start_time = time .monotonic ()
5711- t = 0.01
5712- while len (multiprocessing .active_children ()) > 1 :
5713- time .sleep (t )
5714- t *= 2
5715- dt = time .monotonic () - start_time
5716- if dt >= 5.0 :
5717- test .support .environment_altered = True
5718- support .print_warning (f"multiprocessing.Manager still has "
5719- f"{ multiprocessing .active_children ()} "
5720- f"active children after { dt } seconds" )
5705+ for _ in support .sleeping_retry (5.0 , error = False ):
5706+ if len (multiprocessing .active_children ()) <= 1 :
57215707 break
5708+ else :
5709+ dt = time .monotonic () - start_time
5710+ support .environment_altered = True
5711+ support .print_warning (f"multiprocessing.Manager still has "
5712+ f"{ multiprocessing .active_children ()} "
5713+ f"active children after { dt :.1f} seconds" )
57225714
57235715 def run_worker (self , worker , obj ):
57245716 self .proc = multiprocessing .Process (target = worker , args = (obj , ))
@@ -6031,17 +6023,15 @@ def tearDownClass(cls):
60316023 # but this can take a bit on slow machines, so wait a few seconds
60326024 # if there are other children too (see #17395)
60336025 start_time = time .monotonic ()
6034- t = 0.01
6035- while len (multiprocessing .active_children ()) > 1 :
6036- time .sleep (t )
6037- t *= 2
6038- dt = time .monotonic () - start_time
6039- if dt >= 5.0 :
6040- test .support .environment_altered = True
6041- support .print_warning (f"multiprocessing.Manager still has "
6042- f"{ multiprocessing .active_children ()} "
6043- f"active children after { dt } seconds" )
6026+ for _ in support .sleeping_retry (5.0 , error = False ):
6027+ if len (multiprocessing .active_children ()) <= 1 :
60446028 break
6029+ else :
6030+ dt = time .monotonic () - start_time
6031+ support .environment_altered = True
6032+ support .print_warning (f"multiprocessing.Manager still has "
6033+ f"{ multiprocessing .active_children ()} "
6034+ f"active children after { dt :.1f} seconds" )
60456035
60466036 gc .collect () # do garbage collection
60476037 if cls .manager ._number_of_objects () != 0 :
0 commit comments