diff options
author | Victor Stinner <vstinner@redhat.com> | 2019-07-05 14:15:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-05 14:15:39 (GMT) |
commit | 8fbeb14312b4c1320d31ad86e69749515879d1c3 (patch) | |
tree | ceccd8ce515360bb685f05e1af635e1d67dea350 /Lib/multiprocessing | |
parent | 0d722f3cd602e5f5492f9c65c8af57ea9d3743b6 (diff) | |
download | cpython-8fbeb14312b4c1320d31ad86e69749515879d1c3.zip cpython-8fbeb14312b4c1320d31ad86e69749515879d1c3.tar.gz cpython-8fbeb14312b4c1320d31ad86e69749515879d1c3.tar.bz2 |
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.
Diffstat (limited to 'Lib/multiprocessing')
-rw-r--r-- | Lib/multiprocessing/forkserver.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Lib/multiprocessing/forkserver.py b/Lib/multiprocessing/forkserver.py index 9b63986..87ebef6 100644 --- a/Lib/multiprocessing/forkserver.py +++ b/Lib/multiprocessing/forkserver.py @@ -39,6 +39,25 @@ class ForkServer(object): 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): |