bpo-36888: Add multiprocessing.parent_process() (GH-13247)

This commit is contained in:
Thomas Moreau 2019-05-20 21:37:05 +02:00 committed by Antoine Pitrou
parent 5ae1c84bcd
commit c09a9f56c0
12 changed files with 155 additions and 20 deletions

View file

@ -49,7 +49,11 @@ class Popen(popen_fork.Popen):
set_spawning_popen(None)
self.sentinel, w = forkserver.connect_to_new_process(self._fds)
self.finalizer = util.Finalize(self, os.close, (self.sentinel,))
# Keep a duplicate of the data pipe's write end as a sentinel of the
# parent process used by the child process.
_parent_w = os.dup(w)
self.finalizer = util.Finalize(self, util.close_fds,
(_parent_w, self.sentinel))
with open(w, 'wb', closefd=True) as f:
f.write(buf.getbuffer())
self.pid = forkserver.read_signed(self.sentinel)