Skip to content

Commit a7715cc

Browse files
pythonGH-100133: fix asyncio subprocess losing stderr and stdout output (python#100154)
1 parent 4994f24 commit a7715cc

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
@@ -686,6 +686,23 @@ async def execute():
686686

687687
self.assertIsNone(self.loop.run_until_complete(execute()))
688688

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

690707
if sys.platform != 'win32':
691708
# 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)