8000 bpo-37421: multiprocessing tests now stop ForkServer (GH-14601) · python/cpython@229f6e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 229f6e8

Browse files
bpo-37421: multiprocessing tests now stop ForkServer (GH-14601)
multiprocessing tests now stop the ForkServer instance if it's running: close the "alive" file descriptor to ask the server to stop and then remove its UNIX address. (cherry picked from commit 8fbeb14) Co-authored-by: Victor Stinner <vstinner@redhat.com>
1 parent b4cd6ba commit 229f6e8

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

Lib/multiprocessing/forkserver.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ def __init__(self):
3939
self._lock = threading.Lock()
4040
self._preload_modules = ['__main__']
4141

42+
def _stop(self):
43+
# Method used by unit tests to stop the server
44+
with self._lock:
45+
self._stop_unlocked()
46+
47+
def _stop_unlocked(self):
48+
if self._forkserver_pid is None:
49+
return
50+
51+
# close the "alive" file descriptor asks the server to stop
52+
os.close(self._forkserver_alive_fd)
53+
self._forkserver_alive_fd = None
54+
55+
os.waitpid(self._forkserver_pid, 0)
56+
self._forkserver_pid = None
57+
58+
os.unlink(self._forkserver_address)
59+
self._forkserver_address = None
60+
4261
def set_forkserver_preload(self, modules_names):
4362
'''Set list of module names to try to load in forkserver process.'''
4463
if not all(type(mod) is str for mod in self._preload_modules):

Lib/test/_test_multiprocessing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5650,7 +5650,13 @@ def tearDownModule():
56505650
# Sleep 500 ms to give time to child processes to complete.
56515651
if need_sleep:
56525652
time.sleep(0.5)
5653+
56535654
multiprocessing.process._cleanup()
5655+
5656+
# Stop the ForkServer process if it's running
5657+
from multiprocessing import forkserver
5658+
forkserver._forkserver._stop()
5659+
56545660
# bpo-37421: Explicitly call _run_finalizers() to remove immediately
56555661
# temporary directories created by multiprocessing.util.get_temp_dir().
56565662
multiprocessing.util._run_finalizers()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
multiprocessing tests now stop the ForkServer instance if it's running: close
2+
the "alive" file descriptor to ask the server to stop and then remove its UNIX
3+
address.

0 commit comments

Comments
 (0)
0