Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit edfdf54

Browse files
committed
(Merge 3.4) asyncio, tulip issue 190: Process.communicate() now ignores
ConnectionResetError too
2 parents 0d35741 + d55b54d commit edfdf54

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

Doc/library/asyncio-subprocess.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ Process
191191
process, or ``None``, if no data should be sent to the child. The type
192192
of *input* must be bytes.
193193

194-
If a :exc:`BrokenPipeError` is raised when writing *input* into stdin,
195-
the exception is ignored. It occurs when the process exits before all
196-
data are written into stdin.
194+
If a :exc:`BrokenPipeError` or :exc:`ConnectionResetError` exception is
195+
raised when writing *input* into stdin, the exception is ignored. It
196+
occurs when the process exits before all data are written into stdin.
197197

198198
:meth:`communicate` returns a tuple ``(stdoutdata, stderrdata)``.
199199

@@ -210,7 +210,8 @@ Process
210210
This method is a :ref:`coroutine <coroutine>`.
211211

212212
.. versionchanged:: 3.4.2
213-
The method now ignores :exc:`BrokenPipeError`.
213+
The method now ignores :exc:`BrokenPipeError` and
214+
:exc:`ConnectionResetError`.
214215

215216
.. method:: kill()
216217

Lib/asyncio/subprocess.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,19 @@ def kill(self):
139139

140140
@coroutine
141141
def _feed_stdin(self, input):
142+
debug = self._loop.get_debug()
142143
self.stdin.write(input)
143-
if self._loop.get_debug():
144+
if debug:
144145
logger.debug('%r communicate: feed stdin (%s bytes)',
145146
self, len(input))
146147
try:
147148
yield from self.stdin.drain()
148-
except BrokenPipeError:
149-
# ignore BrokenPipeError
150-
pass
149+
except (BrokenPipeError, ConnectionResetError) as exc:
150+
# communicate() ignores BrokenPipeError and ConnectionResetError
151+
if debug:
152+
logger.debug('%r communicate: stdin got %r', self, exc)
151153

152-
if self._loop.get_debug():
154+
if debug:
153155
logger.debug('%r communicate: close stdin', self)
154156
self.stdin.close()
155157

0 commit comments

Comments
 (0)