]> granicus.if.org Git - python/commitdiff
asyncio, tulip issue 190: Process.communicate() now ignores
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 17 Jul 2014 11:12:03 +0000 (13:12 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 17 Jul 2014 11:12:03 +0000 (13:12 +0200)
ConnectionResetError too

Doc/library/asyncio-subprocess.rst
Lib/asyncio/subprocess.py

index f0ffbf0b8ecd630d2553362d1a314309338a897d..b6532618266b5f67b1f380c541944a512354c780 100644 (file)
@@ -191,9 +191,9 @@ Process
       process, or ``None``, if no data should be sent to the child.  The type
       of *input* must be bytes.
 
-      If a :exc:`BrokenPipeError` is raised when writing *input* into stdin,
-      the exception is ignored. It occurs when the process exits before all
-      data are written into stdin.
+      If a :exc:`BrokenPipeError` or :exc:`ConnectionResetError` exception is
+      raised when writing *input* into stdin, the exception is ignored. It
+      occurs when the process exits before all data are written into stdin.
 
       :meth:`communicate` returns a tuple ``(stdoutdata, stderrdata)``.
 
@@ -210,7 +210,8 @@ Process
       This method is a :ref:`coroutine <coroutine>`.
 
       .. versionchanged:: 3.4.2
-         The method now ignores :exc:`BrokenPipeError`.
+         The method now ignores :exc:`BrokenPipeError` and
+         :exc:`ConnectionResetError`.
 
    .. method:: kill()
 
index 23d6b4da92ba6f3a1ba77836985475795ebc932e..e4c14995a743ba04603c4d21b0fbf23c2b10c30f 100644 (file)
@@ -139,17 +139,19 @@ class Process:
 
     @coroutine
     def _feed_stdin(self, input):
+        debug = self._loop.get_debug()
         self.stdin.write(input)
-        if self._loop.get_debug():
+        if debug:
             logger.debug('%r communicate: feed stdin (%s bytes)',
                         self, len(input))
         try:
             yield from self.stdin.drain()
-        except BrokenPipeError:
-            # ignore BrokenPipeError
-            pass
+        except (BrokenPipeError, ConnectionResetError) as exc:
+            # communicate() ignores BrokenPipeError and ConnectionResetError
+            if debug:
+                logger.debug('%r communicate: stdin got %r', self, exc)
 
-        if self._loop.get_debug():
+        if debug:
             logger.debug('%r communicate: close stdin', self)
         self.stdin.close()