mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
[3.14] gh-118981: multiprocessing.popen_spawn_posix, fix potential hang (gh-118982) (GH-138605)
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).
(cherry picked from commit 8ed5a2b56c)
Co-authored-by: Albert Zeyer <albzey@gmail.com>
This commit is contained in:
parent
32233d68d8
commit
3013683e99
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())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue