diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-22 13:29:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-22 13:29:42 (GMT) |
commit | cbbdf2c1440c804adcfc32ea0470865b3b3b8eb2 (patch) | |
tree | 9b6bcd31449a0045ac099e6e1a408670bcd58ec2 /Lib/asyncio | |
parent | 46b63ced2564ad6c3d7b65e0ea1f04fd5c7d2959 (diff) | |
download | cpython-cbbdf2c1440c804adcfc32ea0470865b3b3b8eb2.zip cpython-cbbdf2c1440c804adcfc32ea0470865b3b3b8eb2.tar.gz cpython-cbbdf2c1440c804adcfc32ea0470865b3b3b8eb2.tar.bz2 |
gh-109709: Fix asyncio test_stdin_broken_pipe() (#109710)
Replace harcoded sleep of 500 ms with synchronization using a pipe.
Fix also Process._feed_stdin(): catch also BrokenPipeError on
stdin.write(input), not only on stdin.drain().
Diffstat (limited to 'Lib/asyncio')
-rw-r--r-- | Lib/asyncio/subprocess.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/asyncio/subprocess.py b/Lib/asyncio/subprocess.py index c4e5ba2..043359b 100644 --- a/Lib/asyncio/subprocess.py +++ b/Lib/asyncio/subprocess.py @@ -147,15 +147,17 @@ class Process: async def _feed_stdin(self, input): debug = self._loop.get_debug() - if input is not None: - self.stdin.write(input) - if debug: - logger.debug( - '%r communicate: feed stdin (%s bytes)', self, len(input)) try: + if input is not None: + self.stdin.write(input) + if debug: + logger.debug( + '%r communicate: feed stdin (%s bytes)', self, len(input)) + await self.stdin.drain() except (BrokenPipeError, ConnectionResetError) as exc: - # communicate() ignores BrokenPipeError and ConnectionResetError + # communicate() ignores BrokenPipeError and ConnectionResetError. + # write() and drain() can raise these exceptions. if debug: logger.debug('%r communicate: stdin got %r', self, exc) |