diff options
author | Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com> | 2023-04-28 00:30:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-28 00:30:26 (GMT) |
commit | 67d140dba72dc2cb661d55878384464de46719e7 (patch) | |
tree | f9459ce8747f0910eb8e62c9c175801378e3175f /Lib/asyncio | |
parent | 424a785a07049924603228b153f746cfe3a983a2 (diff) | |
download | cpython-67d140dba72dc2cb661d55878384464de46719e7.zip cpython-67d140dba72dc2cb661d55878384464de46719e7.tar.gz cpython-67d140dba72dc2cb661d55878384464de46719e7.tar.bz2 |
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.
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/subprocess.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/asyncio/subprocess.py b/Lib/asyncio/subprocess.py index cd10231..50727ca 100644 --- a/Lib/asyncio/subprocess.py +++ b/Lib/asyncio/subprocess.py @@ -144,10 +144,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: @@ -180,7 +181,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() |