From 7700a54b60adf67a07b8024d5a79d5444d89a0da Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Thu, 22 May 2025 18:17:17 +0530 Subject: [PATCH 1/3] avoid calling connection lost callbacks when loop is closed --- Lib/asyncio/base_subprocess.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py index 9c2ba679ce2bf1..ae8b51f8977943 100644 --- a/Lib/asyncio/base_subprocess.py +++ b/Lib/asyncio/base_subprocess.py @@ -104,7 +104,12 @@ def close(self): for proto in self._pipes.values(): if proto is None: continue - proto.pipe.close() + # See https://github.com/python/cpython/issues/114177 + # skip closing the pipe if loop is already closed + # this can happen e.g. when loop is closed immediately after + # process is killed + if self._loop and not self._loop.is_closed(): + proto.pipe.close() if (self._proc is not None and # has the child process finished? From 6f52c06484efe4e96cbaf56985b3d2cc6658be49 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 22 May 2025 13:10:38 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-05-22-13-10-32.gh-issue-114177.3TYUJ3.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-05-22-13-10-32.gh-issue-114177.3TYUJ3.rst diff --git a/Misc/NEWS.d/next/Library/2025-05-22-13-10-32.gh-issue-114177.3TYUJ3.rst b/Misc/NEWS.d/next/Library/2025-05-22-13-10-32.gh-issue-114177.3TYUJ3.rst new file mode 100644 index 00000000000000..c98fde5fb04f5c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-22-13-10-32.gh-issue-114177.3TYUJ3.rst @@ -0,0 +1 @@ +Fix :mod:`asyncio` to not close subprocess pipes which would otherwise error out when the event loop is already closed. From 60cef457d4adf7fdd91b9c954f1d8409b083a864 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Fri, 23 May 2025 09:36:52 +0530 Subject: [PATCH 3/3] Update Lib/asyncio/base_subprocess.py Co-authored-by: Guido van Rossum --- Lib/asyncio/base_subprocess.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py index ae8b51f8977943..d40af422e614c1 100644 --- a/Lib/asyncio/base_subprocess.py +++ b/Lib/asyncio/base_subprocess.py @@ -104,7 +104,7 @@ def close(self): for proto in self._pipes.values(): if proto is None: continue - # See https://github.com/python/cpython/issues/114177 + # See gh-114177 # skip closing the pipe if loop is already closed # this can happen e.g. when loop is closed immediately after # process is killed