Skip to content

Commit ae8520c

Browse files
GH-100133: fix asyncio subprocess losing stderr and stdout output (GH-100154)
(cherry picked from commit a7715cc) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
1 parent bed1d14 commit ae8520c

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

Lib/asyncio/base_subprocess.py

-3
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@ def _process_exited(self, returncode):
215215
# object. On Python 3.6, it is required to avoid a ResourceWarning.
216216
self._proc.returncode = returncode
217217
self._call(self._protocol.process_exited)
218-
for p in self._pipes.values():
219-
if p is not None:
220-
p.pipe.close()
221218

222219
self._try_finish()
223220

Lib/test/test_asyncio/test_subprocess.py

+17
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,23 @@ async def execute():
684684

685685
self.assertIsNone(self.loop.run_until_complete(execute()))
686686

687+
def test_subprocess_communicate_stdout(self):
688+
# See https://github.com/python/cpython/issues/100133
689+
async def get_command_stdout(cmd, *args):
690+
proc = await asyncio.create_subprocess_exec(
691+
cmd, *args, stdout=asyncio.subprocess.PIPE,
692+
)
693+
stdout, _ = await proc.communicate()
694+
return stdout.decode().strip()
695+
696+
async def main():
697+
outputs = [f'foo{i}' for i in range(10)]
698+
res = await asyncio.gather(*[get_command_stdout(sys.executable, '-c',
699+
f'print({out!r})') for out in outputs])
700+
self.assertEqual(res, outputs)
701+
702+
self.loop.run_until_complete(main())
703+
687704

688705
if sys.platform != 'win32':
689706
# Unix
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix regression in :mod:`asyncio` where a subprocess would sometimes lose data received from pipe.

0 commit comments

Comments
 (0)