mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
GH-100133: fix asyncio
subprocess losing stderr
and stdout
output (GH-100154)
(cherry picked from commit a7715ccfba
)
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
This commit is contained in:
parent
bed1d141a9
commit
ae8520c709
3 changed files with 18 additions and 3 deletions
|
@ -215,9 +215,6 @@ class BaseSubprocessTransport(transports.SubprocessTransport):
|
|||
# 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()
|
||||
|
||||
|
|
|
@ -684,6 +684,23 @@ class SubprocessMixin:
|
|||
|
||||
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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix regression in :mod:`asyncio` where a subprocess would sometimes lose data received from pipe.
|
Loading…
Add table
Add a link
Reference in a new issue