@@ -4376,18 +4376,13 @@ def test_shared_memory_cleaned_after_process_termination(self):
4376
4376
p .terminate ()
4377
4377
p .wait ()
4378
4378
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 ):
4384
4382
try :
4385
4383
smm = shared_memory .SharedMemory (name , create = False )
4386
4384
except FileNotFoundError :
4387
4385
break
4388
- else :
4389
- raise AssertionError ("A SharedMemory segment was leaked after"
4390
- " a process was abruptly terminated." )
4391
4386
4392
4387
if os .name == 'posix' :
4393
4388
# Without this line it was raising warnings like:
@@ -5458,20 +5453,18 @@ def create_and_register_resource(rtype):
5458
5453
p .terminate ()
5459
5454
p .wait ()
5460
5455
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 ):
5464
5460
try :
5465
5461
_resource_unlink (name2 , rtype )
5466
5462
except OSError as e :
5467
5463
# docs say it should be ENOENT, but OSX seems to give
5468
5464
# EINVAL
5469
5465
self .assertIn (e .errno , (errno .ENOENT , errno .EINVAL ))
5470
5466
break
5471
- else :
5472
- raise AssertionError (
5473
- f"A { rtype } resource was leaked after a process was "
5474
- f"abruptly terminated." )
5467
+
5475
5468
err = p .stderr .read ().decode ('utf-8' )
5476
5469
p .stderr .close ()
5477
5470
expected = ('resource_tracker: There appear to be 2 leaked {} '
@@ -5707,18 +5700,17 @@ def wait_proc_exit(self):
5707
5700
# but this can take a bit on slow machines, so wait a few seconds
5708
5701
# if there are other children too (see #17395).
5709
5702
join_process (self .proc )
5703
+
5710
5704
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 :
5721
5707
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" )
5722
5714
5723
5715
def run_worker (self , worker , obj ):
5724
5716
self .proc = multiprocessing .Process (target = worker , args = (obj , ))
@@ -6031,17 +6023,15 @@ def tearDownClass(cls):
6031
6023
# but this can take a bit on slow machines, so wait a few seconds
6032
6024
# if there are other children too (see #17395)
6033
6025
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 :
6044
6028
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" )
6045
6035
6046
6036
gc .collect () # do garbage collection
6047
6037
if cls .manager ._number_of_objects () != 0 :
0 commit comments