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 8fbeb14312)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
This commit is contained in:
Miss Islington (bot) 2019-07-05 07:35:38 -07:00 committed by GitHub
parent b4cd6ba1a0
commit 229f6e85f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 0 deletions

View file

@ -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):