File tree Expand file tree Collapse file tree 5 files changed +42
-21
lines changed Expand file tree Collapse file tree 5 files changed +42
-21
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,19 @@ def __init__(self):
50
50
self ._fd = None
51
51
self ._pid = None
52
52
53
+ def _stop (self ):
54
+ with self ._lock :
55
+ if self ._fd is None :
56
+ # not running
57
+ return
58
+
59
+ # closing the "alive" file descriptor stops main()
60
+ os .close (self ._fd )
61
+ self ._fd = None
62
+
63
+ os .waitpid (self ._pid , 0 )
64
+ self ._pid = None
65
+
53
66
def getfd (self ):
54
67
self .ensure_running ()
55
68
return self ._fd
Original file line number Diff line number Diff line change @@ -439,3 +439,28 @@ def close_fds(*fds):
439
439
"""Close each file descriptor given as an argument"""
440
440
for fd in fds :
441
441
os .close (fd )
442
+
443
+
444
+ def _cleanup_tests ():
445
+ """Cleanup multiprocessing resources when multiprocessing tests
446
+ completed."""
447
+
448
+ from test import support
449
+
450
+ # cleanup multiprocessing
451
+ process ._cleanup ()
452
+
453
+ # Stop the ForkServer process if it's running
454
+ from multiprocessing import forkserver
455
+ forkserver ._forkserver ._stop ()
456
+
457
+ # Stop the ResourceTracker process if it's running
458
+ from multiprocessing import resource_tracker
459
+ resource_tracker ._resource_tracker ._stop ()
460
+
461
+ # bpo-37421: Explicitly call _run_finalizers() to remove immediately
462
+ # temporary directories created by multiprocessing.util.get_temp_dir().
463
+ _run_finalizers ()
464
+ support .gc_collect ()
465
+
466
+ support .reap_children ()
Original file line number Diff line number Diff line change @@ -5695,16 +5695,7 @@ def tearDownModule():
5695
5695
if need_sleep :
5696
5696
time .sleep (0.5 )
5697
5697
5698
- multiprocessing .process ._cleanup ()
5699
-
5700
- # Stop the ForkServer process if it's running
5701
- from multiprocessing import forkserver
5702
- forkserver ._forkserver ._stop ()
5703
-
5704
- # bpo-37421: Explicitly call _run_finalizers() to remove immediately
5705
- # temporary directories created by multiprocessing.util.get_temp_dir().
5706
- multiprocessing .util ._run_finalizers ()
5707
- test .support .gc_collect ()
5698
+ multiprocessing .util ._cleanup_tests ()
5708
5699
5709
5700
remote_globs ['setUpModule' ] = setUpModule
5710
5701
remote_globs ['tearDownModule' ] = tearDownModule
Original file line number Diff line number Diff line change @@ -1306,17 +1306,7 @@ def setUpModule():
1306
1306
1307
1307
def tearDownModule ():
1308
1308
support .threading_cleanup (* _threads_key )
1309
- support .reap_children ()
1310
-
1311
- # cleanup multiprocessing
1312
- multiprocessing .process ._cleanup ()
1313
- # Stop the ForkServer process if it's running
1314
- from multiprocessing import forkserver
1315
- forkserver ._forkserver ._stop ()
1316
- # bpo-37421: Explicitly call _run_finalizers() to remove immediately
1317
- # temporary directories created by multiprocessing.util.get_temp_dir().
1318
- multiprocessing .util ._run_finalizers ()
1319
- support .gc_collect ()
1309
+ multiprocessing .util ._cleanup_tests ()
1320
1310
1321
1311
1322
1312
if __name__ == "__main__" :
Original file line number Diff line number Diff line change
1
+ Multiprocessing and concurrent.futures tests now stop the resource tracker
2
+ process when tests complete.
You can’t perform that action at this time.
0 commit comments