8000 [3.8] bpo-37421: multiprocessing tests now stop ForkServer (GH-14601) by miss-islington · Pull Request #14602 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.8] bpo-37421: multiprocessing tests now stop ForkServer (GH-14601) #14602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Lib/multiprocessing/forkserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ def __init__(self):
self._lock = threading.Lock()
self._preload_modules = ['__main__']

def _stop(self):
# Method used by unit tests to stop the server
with self._lock:
self._stop_unlocked()

def _stop_unlocked(self):
if self._forkserver_pid is None:
return

# close the "alive" file descriptor asks the server to stop
os.close(self._forkserver_alive_fd)
self._forkserver_alive_fd = None

os.waitpid(self._forkserver_pid, 0)
self._forkserver_pid = None

os.unlink(self._forkserver_address)
self._forkserver_address = None

def set_forkserver_preload(self, modules_names):
'''Set list of module names to try to load in forkserver process.'''
if not all(type(mod) is str for mod in self._preload_modules):
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5650,7 +5650,13 @@ def tearDownModule():
# Sleep 500 ms to give time to child processes to complete.
if need_sleep:
time.sleep(0.5)

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()
Expand Down
5B95
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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.
0