mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
gh-118981: multiprocessing.popen_spawn_posix, fix potential hang (gh-118982)
fix potential hang. It can happen that the child crashes right in the beginning for whatever reason. In this case, the parent will hang when writing into the pipe, because the child fd is not closed yet. The normal pattern is to close the child fds right after the child proc is forked/executed/spawned, so when the child dies, then also the pipes will be closed, and there will be no hang (the parent gets SIGPIPE instead).
This commit is contained in:
parent
c117b03385
commit
8ed5a2b56c
2 changed files with 6 additions and 0 deletions
|
|
@ -57,6 +57,10 @@ def _launch(self, process_obj):
|
|||
self._fds.extend([child_r, child_w])
|
||||
self.pid = util.spawnv_passfds(spawn.get_executable(),
|
||||
cmd, self._fds)
|
||||
os.close(child_r)
|
||||
child_r = None
|
||||
os.close(child_w)
|
||||
child_w = None
|
||||
self.sentinel = parent_r
|
||||
with open(parent_w, 'wb', closefd=False) as f:
|
||||
f.write(fp.getbuffer())
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fix potential hang in ``multiprocessing.popen_spawn_posix`` that can happen
|
||||
when the child proc dies early by closing the child fds right away.
|
||||
Loading…
Add table
Add a link
Reference in a new issue