bpo-38546: multiprocessing tests stop the resource tracker (GH-17641)
Multiprocessing and concurrent.futures tests now stop the resource tracker process when tests complete. Add ResourceTracker._stop() method to multiprocessing.resource_tracker. Add _cleanup_tests() helper function to multiprocessing.util: share code between multiprocessing and concurrent.futures tests.
This commit is contained in:
parent
630c8df5cf
commit
9707e8e22d
|
@ -50,6 +50,19 @@ class ResourceTracker(object):
|
||||||
self._fd = None
|
self._fd = None
|
||||||
self._pid = None
|
self._pid = None
|
||||||
|
|
||||||
|
def _stop(self):
|
||||||
|
with self._lock:
|
||||||
|
if self._fd is None:
|
||||||
|
# not running
|
||||||
|
return
|
||||||
|
|
||||||
|
# closing the "alive" file descriptor stops main()
|
||||||
|
os.close(self._fd)
|
||||||
|
self._fd = None
|
||||||
|
|
||||||
|
os.waitpid(self._pid, 0)
|
||||||
|
self._pid = None
|
||||||
|
|
||||||
def getfd(self):
|
def getfd(self):
|
||||||
self.ensure_running()
|
self.ensure_running()
|
||||||
return self._fd
|
return self._fd
|
||||||
|
|
|
@ -439,3 +439,28 @@ def close_fds(*fds):
|
||||||
"""Close each file descriptor given as an argument"""
|
"""Close each file descriptor given as an argument"""
|
||||||
for fd in fds:
|
for fd in fds:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
|
|
||||||
|
def _cleanup_tests():
|
||||||
|
"""Cleanup multiprocessing resources when multiprocessing tests
|
||||||
|
completed."""
|
||||||
|
|
||||||
|
from test import support
|
||||||
|
|
||||||
|
# cleanup multiprocessing
|
||||||
|
process._cleanup()
|
||||||
|
|
||||||
|
# Stop the ForkServer process if it's running
|
||||||
|
from multiprocessing import forkserver
|
||||||
|
forkserver._forkserver._stop()
|
||||||
|
|
||||||
|
# Stop the ResourceTracker process if it's running
|
||||||
|
from multiprocessing import resource_tracker
|
||||||
|
resource_tracker._resource_tracker._stop()
|
||||||
|
|
||||||
|
# bpo-37421: Explicitly call _run_finalizers() to remove immediately
|
||||||
|
# temporary directories created by multiprocessing.util.get_temp_dir().
|
||||||
|
_run_finalizers()
|
||||||
|
support.gc_collect()
|
||||||
|
|
||||||
|
support.reap_children()
|
||||||
|
|
|
@ -5695,16 +5695,7 @@ def install_tests_in_module_dict(remote_globs, start_method):
|
||||||
if need_sleep:
|
if need_sleep:
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
multiprocessing.process._cleanup()
|
multiprocessing.util._cleanup_tests()
|
||||||
|
|
||||||
# Stop the ForkServer process if it's running
|
|
||||||
from multiprocessing import forkserver
|
|
||||||
forkserver._forkserver._stop()
|
|
||||||
|
|
||||||
# bpo-37421: Explicitly call _run_finalizers() to remove immediately
|
|
||||||
# temporary directories created by multiprocessing.util.get_temp_dir().
|
|
||||||
multiprocessing.util._run_finalizers()
|
|
||||||
test.support.gc_collect()
|
|
||||||
|
|
||||||
remote_globs['setUpModule'] = setUpModule
|
remote_globs['setUpModule'] = setUpModule
|
||||||
remote_globs['tearDownModule'] = tearDownModule
|
remote_globs['tearDownModule'] = tearDownModule
|
||||||
|
|
|
@ -1306,17 +1306,7 @@ def setUpModule():
|
||||||
|
|
||||||
def tearDownModule():
|
def tearDownModule():
|
||||||
support.threading_cleanup(*_threads_key)
|
support.threading_cleanup(*_threads_key)
|
||||||
support.reap_children()
|
multiprocessing.util._cleanup_tests()
|
||||||
|
|
||||||
# cleanup multiprocessing
|
|
||||||
multiprocessing.process._cleanup()
|
|
||||||
# Stop the ForkServer process if it's running
|
|
||||||
from multiprocessing import forkserver
|
|
||||||
forkserver._forkserver._stop()
|
|
||||||
# bpo-37421: Explicitly call _run_finalizers() to remove immediately
|
|
||||||
# temporary directories created by multiprocessing.util.get_temp_dir().
|
|
||||||
multiprocessing.util._run_finalizers()
|
|
||||||
support.gc_collect()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Multiprocessing and concurrent.futures tests now stop the resource tracker
|
||||||
|
process when tests complete.
|
Loading…
Reference in New Issue