[Python-checkins] GH-100133: fix `asyncio` subprocess losing `stderr` and `stdout` output (GH-100154)
miss-islington
webhook-mailer at python.org
Wed Dec 21 05:24:25 EST 2022
https://github.com/python/cpython/commit/ae8520c70992710903819f24dbce4e7dd05d7ea8
commit: ae8520c70992710903819f24dbce4e7dd05d7ea8
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-12-21T02:24:19-08:00
summary:
GH-100133: fix `asyncio` subprocess losing `stderr` and `stdout` output (GH-100154)
(cherry picked from commit a7715ccfba5b86ab09f86ec56ac3755c93b46b48)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
files:
A Misc/NEWS.d/next/Library/2022-12-10-08-36-07.gh-issue-100133.g-zQlp.rst
M Lib/asyncio/base_subprocess.py
M Lib/test/test_asyncio/test_subprocess.py
diff --git a/Lib/asyncio/base_subprocess.py b/Lib/asyncio/base_subprocess.py
index e15bb4141fc0..4c9b0dd5653c 100644
--- a/Lib/asyncio/base_subprocess.py
+++ b/Lib/asyncio/base_subprocess.py
@@ -215,9 +215,6 @@ def _process_exited(self, returncode):
# object. On Python 3.6, it is required to avoid a ResourceWarning.
self._proc.returncode = returncode
self._call(self._protocol.process_exited)
- for p in self._pipes.values():
- if p is not None:
- p.pipe.close()
self._try_finish()
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index f71ad72f999e..bea2314a5286 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -684,6 +684,23 @@ async def execute():
self.assertIsNone(self.loop.run_until_complete(execute()))
+ def test_subprocess_communicate_stdout(self):
+ # See https://github.com/python/cpython/issues/100133
+ async def get_command_stdout(cmd, *args):
+ proc = await asyncio.create_subprocess_exec(
+ cmd, *args, stdout=asyncio.subprocess.PIPE,
+ )
+ stdout, _ = await proc.communicate()
+ return stdout.decode().strip()
+
+ async def main():
+ outputs = [f'foo{i}' for i in range(10)]
+ res = await asyncio.gather(*[get_command_stdout(sys.executable, '-c',
+ f'print({out!r})') for out in outputs])
+ self.assertEqual(res, outputs)
+
+ self.loop.run_until_complete(main())
+
if sys.platform != 'win32':
# Unix
diff --git a/Misc/NEWS.d/next/Library/2022-12-10-08-36-07.gh-issue-100133.g-zQlp.rst b/Misc/NEWS.d/next/Library/2022-12-10-08-36-07.gh-issue-100133.g-zQlp.rst
new file mode 100644
index 000000000000..881e6ed80fed
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-12-10-08-36-07.gh-issue-100133.g-zQlp.rst
@@ -0,0 +1 @@
+Fix regression in :mod:`asyncio` where a subprocess would sometimes lose data received from pipe.
More information about the Python-checkins
mailing list