mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-83925: Make asyncio.subprocess communicate similar to non-asyncio (#18650)
subprocess's communicate(None) closes stdin of the child process, after sending no (extra) data. Make asyncio variant do the same. This fixes issues with processes that waits for EOF on stdin before continuing.
This commit is contained in:
parent
424a785a07
commit
67d140dba7
4 changed files with 32 additions and 7 deletions
|
@ -151,6 +151,24 @@ class SubprocessMixin:
|
|||
self.assertEqual(exitcode, 0)
|
||||
self.assertEqual(stdout, b'some data')
|
||||
|
||||
def test_communicate_none_input(self):
|
||||
args = PROGRAM_CAT
|
||||
|
||||
async def run():
|
||||
proc = await asyncio.create_subprocess_exec(
|
||||
*args,
|
||||
stdin=subprocess.PIPE,
|
||||
stdout=subprocess.PIPE,
|
||||
)
|
||||
stdout, stderr = await proc.communicate()
|
||||
return proc.returncode, stdout
|
||||
|
||||
task = run()
|
||||
task = asyncio.wait_for(task, support.LONG_TIMEOUT)
|
||||
exitcode, stdout = self.loop.run_until_complete(task)
|
||||
self.assertEqual(exitcode, 0)
|
||||
self.assertEqual(stdout, b'')
|
||||
|
||||
def test_shell(self):
|
||||
proc = self.loop.run_until_complete(
|
||||
asyncio.create_subprocess_shell('exit 7')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue