bpo-39744: make asyncio.subprocess communicate similar to non-asyncio one

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:
Marek Marczykowski-Górecki 2020-02-24 23:18:41 +01:00
parent 8af4712a16
commit fbb554663d
No known key found for this signature in database
GPG Key ID: BB2ED46ACD2C6CF7
2 changed files with 7 additions and 5 deletions

View File

@ -145,10 +145,11 @@ class Process:
async def _feed_stdin(self, input):
debug = self._loop.get_debug()
self.stdin.write(input)
if debug:
logger.debug(
'%r communicate: feed stdin (%s bytes)', self, len(input))
if input is not None:
self.stdin.write(input)
if debug:
logger.debug(
'%r communicate: feed stdin (%s bytes)', self, len(input))
try:
await self.stdin.drain()
except (BrokenPipeError, ConnectionResetError) as exc:
@ -181,7 +182,7 @@ class Process:
return output
async def communicate(self, input=None):
if input is not None:
if self.stdin is not None:
stdin = self._feed_stdin(input)
else:
stdin = self._noop()

View File

@ -0,0 +1 @@
Make func:`asyncio.subprocess.Process.communicate` close subprocess's stdin even when called with input=None