[Python-checkins] cpython (3.4): asyncio, tulip issue 190: Process.communicate() now ignores

victor.stinner python-checkins at python.org
Thu Jul 17 13:12:29 CEST 2014


http://hg.python.org/cpython/rev/cb327c64cffb
changeset:   91715:cb327c64cffb
branch:      3.4
parent:      91713:244ab7f41065
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Thu Jul 17 13:12:03 2014 +0200
summary:
  asyncio, tulip issue 190: Process.communicate() now ignores
ConnectionResetError too

files:
  Doc/library/asyncio-subprocess.rst |   9 +++++----
  Lib/asyncio/subprocess.py          |  12 +++++++-----
  2 files changed, 12 insertions(+), 9 deletions(-)


diff --git a/Doc/library/asyncio-subprocess.rst b/Doc/library/asyncio-subprocess.rst
--- a/Doc/library/asyncio-subprocess.rst
+++ b/Doc/library/asyncio-subprocess.rst
@@ -191,9 +191,9 @@
       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 @@
       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()
 
diff --git a/Lib/asyncio/subprocess.py b/Lib/asyncio/subprocess.py
--- a/Lib/asyncio/subprocess.py
+++ b/Lib/asyncio/subprocess.py
@@ -139,17 +139,19 @@
 
     @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()
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list