[Python-checkins] GH-85760: Fix race in calling process_exited callback too early (#97009)

gvanrossum webhook-mailer at python.org
Thu Sep 22 12:43:55 EDT 2022


https://github.com/python/cpython/commit/282edd7b2a74c4dfe1bfe3c5b1d30f9c21d554d6
commit: 282edd7b2a74c4dfe1bfe3c5b1d30f9c21d554d6
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: gvanrossum <gvanrossum at gmail.com>
date: 2022-09-22T09:43:47-07:00
summary:

GH-85760: Fix race in calling process_exited callback too early (#97009)

files:
A Misc/NEWS.d/next/Library/2022-09-22-11-50-29.gh-issue-85760.DETTPd.rst
M Lib/asyncio/unix_events.py

diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index cf7683fee646..96e6d73a7597 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -223,7 +223,8 @@ async def _make_subprocess_transport(self, protocol, args, shell,
         return transp
 
     def _child_watcher_callback(self, pid, returncode, transp):
-        self.call_soon_threadsafe(transp._process_exited, returncode)
+        # Skip one iteration for callbacks to be executed
+        self.call_soon_threadsafe(self.call_soon, transp._process_exited, returncode)
 
     async def create_unix_connection(
             self, protocol_factory, path=None, *,
diff --git a/Misc/NEWS.d/next/Library/2022-09-22-11-50-29.gh-issue-85760.DETTPd.rst b/Misc/NEWS.d/next/Library/2022-09-22-11-50-29.gh-issue-85760.DETTPd.rst
new file mode 100644
index 000000000000..af8ae2026f16
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-09-22-11-50-29.gh-issue-85760.DETTPd.rst
@@ -0,0 +1 @@
+Fix race condition in :mod:`asyncio` where :meth:`~asyncio.SubprocessProtocol.process_exited` called before the :meth:`~asyncio.SubprocessProtocol.pipe_data_received` leading to inconsistent output. Patch by Kumar Aditya.



More information about the Python-checkins mailing list