https://github.com/python/cpython/commit/5987ebc7748d520d6dab4c53e22ef24258a6e69a
commit: 5987ebc7748d520d6dab4c53e22ef24258a6e69a
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: kumaraditya303 <[email protected]>
date: 2025-05-23T04:56:14Z
summary:

[3.13] gh-114177: avoid calling connection lost callbacks when loop is already 
closed in asyncio subprocess (GH-134508) (#134562)

gh-114177: avoid calling connection lost callbacks when loop is already closed 
in asyncio subprocess (GH-134508)
(cherry picked from commit 5804ee7b467d86131be3ff7d569443efb0d0f9fd)

Co-authored-by: Kumar Aditya <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-05-22-13-10-32.gh-issue-114177.3TYUJ3.rst
M Lib/asyncio/base_subprocess.py

diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py
index 9c2ba679ce2bf1..d40af422e614c1 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 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
+            if self._loop and not self._loop.is_closed():
+                proto.pipe.close()
 
         if (self._proc is not None and
                 # has the child process finished?
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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to