@@ -4313,18 +4313,13 @@ def test_shared_memory_cleaned_after_process_termination(self):
43134313            p .terminate ()
43144314            p .wait ()
43154315
4316-             deadline  =  time .monotonic () +  support .LONG_TIMEOUT 
4317-             t  =  0.1 
4318-             while  time .monotonic () <  deadline :
4319-                 time .sleep (t )
4320-                 t  =  min (t * 2 , 5 )
4316+             err_msg  =  ("A SharedMemory segment was leaked after " 
4317+                        "a process was abruptly terminated" )
4318+             for  _  in  support .sleeping_retry (support .LONG_TIMEOUT , err_msg ):
43214319                try :
43224320                    smm  =  shared_memory .SharedMemory (name , create = False )
43234321                except  FileNotFoundError :
43244322                    break 
4325-             else :
4326-                 raise  AssertionError ("A SharedMemory segment was leaked after" 
4327-                                      " a process was abruptly terminated." )
43284323
43294324            if  os .name  ==  'posix' :
43304325                # Without this line it was raising warnings like: 
@@ -5334,20 +5329,18 @@ def create_and_register_resource(rtype):
53345329                p .terminate ()
53355330                p .wait ()
53365331
5337-                 deadline  =  time .monotonic () +  support .LONG_TIMEOUT 
5338-                 while  time .monotonic () <  deadline :
5339-                     time .sleep (.5 )
5332+                 err_msg  =  (f"A { rtype }  
5333+                            f"abruptly terminated" )
5334+                 for  _  in  support .sleeping_retry (support .SHORT_TIMEOUT ,
5335+                                                   err_msg ):
53405336                    try :
53415337                        _resource_unlink (name2 , rtype )
53425338                    except  OSError  as  e :
53435339                        # docs say it should be ENOENT, but OSX seems to give 
53445340                        # EINVAL 
53455341                        self .assertIn (e .errno , (errno .ENOENT , errno .EINVAL ))
53465342                        break 
5347-                 else :
5348-                     raise  AssertionError (
5349-                         f"A { rtype }  
5350-                         f"abruptly terminated." )
5343+ 
53515344                err  =  p .stderr .read ().decode ('utf-8' )
53525345                p .stderr .close ()
53535346                expected  =  ('resource_tracker: There appear to be 2 leaked {} ' 
@@ -5575,18 +5568,17 @@ def wait_proc_exit(self):
55755568        # but this can take a bit on slow machines, so wait a few seconds 
55765569        # if there are other children too (see #17395). 
55775570        join_process (self .proc )
5571+ 
55785572        start_time  =  time .monotonic ()
5579-         t  =  0.01 
5580-         while  len (multiprocessing .active_children ()) >  1 :
5581-             time .sleep (t )
5582-             t  *=  2 
5583-             dt  =  time .monotonic () -  start_time 
5584-             if  dt  >=  5.0 :
5585-                 test .support .environment_altered  =  True 
5586-                 support .print_warning (f"multiprocessing.Manager still has " 
5587-                                       f"{ multiprocessing .active_children ()}  
5588-                                       f"active children after { dt }  )
5573+         for  _  in  support .sleeping_retry (5.0 , error = False ):
5574+             if  len (multiprocessing .active_children ()) <=  1 :
55895575                break 
5576+         else :
5577+             dt  =  time .monotonic () -  start_time 
5578+             support .environment_altered  =  True 
5579+             support .print_warning (f"multiprocessing.Manager still has " 
5580+                                   f"{ multiprocessing .active_children ()}  
5581+                                   f"active children after { dt :.1f}  )
55905582
55915583    def  run_worker (self , worker , obj ):
55925584        self .proc  =  multiprocessing .Process (target = worker , args = (obj , ))
@@ -5884,17 +5876,15 @@ def tearDownClass(cls):
58845876        # but this can take a bit on slow machines, so wait a few seconds 
58855877        # if there are other children too (see #17395) 
58865878        start_time  =  time .monotonic ()
5887-         t  =  0.01 
5888-         while  len (multiprocessing .active_children ()) >  1 :
5889-             time .sleep (t )
5890-             t  *=  2 
5891-             dt  =  time .monotonic () -  start_time 
5892-             if  dt  >=  5.0 :
5893-                 test .support .environment_altered  =  True 
5894-                 support .print_warning (f"multiprocessing.Manager still has " 
5895-                                       f"{ multiprocessing .active_children ()}  
5896-                                       f"active children after { dt }  )
5879+         for  _  in  support .sleeping_retry (5.0 , error = False ):
5880+             if  len (multiprocessing .active_children ()) <=  1 :
58975881                break 
5882+         else :
5883+             dt  =  time .monotonic () -  start_time 
5884+             support .environment_altered  =  True 
5885+             support .print_warning (f"multiprocessing.Manager still has " 
5886+                                   f"{ multiprocessing .active_children ()}  
5887+                                   f"active children after { dt :.1f}  )
58985888
58995889        gc .collect ()                       # do garbage collection 
59005890        if  cls .manager ._number_of_objects () !=  0 :
0 commit comments