From 0a5541514ec9f1be9d879b7c5a9e5bacba4a7ae5 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Mon, 13 May 2024 09:37:14 +0200 Subject: [PATCH 1/2] fix potential hang Fix gh-118981 --- Lib/multiprocessing/popen_spawn_posix.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Lib/multiprocessing/popen_spawn_posix.py b/Lib/multiprocessing/popen_spawn_posix.py index 24b8634523e5f2..cccd659ae77637 100644 --- a/Lib/multiprocessing/popen_spawn_posix.py +++ b/Lib/multiprocessing/popen_spawn_posix.py @@ -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()) From 4c9fd26c35fed4f4bc57d6abacd565b1354efc05 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Mon, 13 May 2024 09:50:36 +0200 Subject: [PATCH 2/2] news --- .../next/Library/2024-05-13-09-50-31.gh-issue-118981.zgOQPv.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-05-13-09-50-31.gh-issue-118981.zgOQPv.rst diff --git a/Misc/NEWS.d/next/Library/2024-05-13-09-50-31.gh-issue-118981.zgOQPv.rst b/Misc/NEWS.d/next/Library/2024-05-13-09-50-31.gh-issue-118981.zgOQPv.rst new file mode 100644 index 00000000000000..72b9f6c9e4eb99 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-05-13-09-50-31.gh-issue-118981.zgOQPv.rst @@ -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.