Skip to content

Commit

Permalink
pythonGH-100133: fix asyncio subprocess losing stderr and `stdout…
Browse files Browse the repository at this point in the history
…` output (python#100154)
  • Loading branch information
kumaraditya303 authored Dec 21, 2022
1 parent 4994f24 commit a7715cc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
3 changes: 0 additions & 3 deletions Lib/asyncio/base_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix regression in :mod:`asyncio` where a subprocess would sometimes lose data received from pipe.

0 comments on commit a7715cc

Please sign in to comment.