@@ -4313,18 +4313,13 @@ def test_shared_memory_cleaned_after_process_termination(self):
4313
4313
p .terminate ()
4314
4314
p .wait ()
4315
4315
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 ):
4321
4319
try :
4322
4320
smm = shared_memory .SharedMemory (name , create = False )
4323
4321
except FileNotFoundError :
4324
4322
break
4325
- else :
4326
- raise AssertionError ("A SharedMemory segment was leaked after"
4327
- " a process was abruptly terminated." )
4328
4323
4329
4324
if os .name == 'posix' :
4330
4325
# Without this line it was raising warnings like:
@@ -5334,20 +5329,18 @@ def create_and_register_resource(rtype):
5334
5329
p .terminate ()
5335
5330
p .wait ()
5336
5331
5337
- deadline = time .monotonic () + support .LONG_TIMEOUT
5338
- while time .monotonic () < deadline :
5339
- time .sleep (.5 )
5332
+ err_msg = (f"A { rtype } resource was leaked after a process was "
5333
+ f"abruptly terminated" )
5334
+ for _ in support .sleeping_retry (support .SHORT_TIMEOUT ,
5335
+ err_msg ):
5340
5336
try :
5341
5337
_resource_unlink (name2 , rtype )
5342
5338
except OSError as e :
5343
5339
# docs say it should be ENOENT, but OSX seems to give
5344
5340
# EINVAL
5345
5341
self .assertIn (e .errno , (errno .ENOENT , errno .EINVAL ))
5346
5342
break
5347
- else :
5348
- raise AssertionError (
5349
- f"A { rtype } resource was leaked after a process was "
5350
- f"abruptly terminated." )
5343
+
5351
5344
err = p .stderr .read ().decode ('utf-8' )
5352
5345
p .stderr .close ()
5353
5346
expected = ('resource_tracker: There appear to be 2 leaked {} '
@@ -5575,18 +5568,17 @@ def wait_proc_exit(self):
5575
5568
# but this can take a bit on slow machines, so wait a few seconds
5576
5569
# if there are other children too (see #17395).
5577
5570
join_process (self .proc )
5571
+
5578
5572
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 } seconds" )
5573
+ for _ in support .sleeping_retry (5.0 , error = False ):
5574
+ if len (multiprocessing .active_children ()) <= 1 :
5589
5575
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} seconds" )
5590
5582
5591
5583
def run_worker (self , worker , obj ):
5592
5584
self .proc = multiprocessing .Process (target = worker , args = (obj , ))
@@ -5884,17 +5876,15 @@ def tearDownClass(cls):
5884
5876
# but this can take a bit on slow machines, so wait a few seconds
5885
5877
# if there are other children too (see #17395)
5886
5878
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 } seconds" )
5879
+ for _ in support .sleeping_retry (5.0 , error = False ):
5880
+ if len (multiprocessing .active_children ()) <= 1 :
5897
5881
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} seconds" )
5898
5888
5899
5889
gc .collect () # do garbage collection
5900
5890
if cls .manager ._number_of_objects () != 0 :
0 commit comments