diff Lib/test/test_subprocess.py @ 71228:dcfacc2d93b4 3.2

Issue #12493: subprocess: communicate() handles EINTR subprocess.Popen.communicate() now also handles EINTR errors if the process has only one pipe.
author Victor Stinner <victor.stinner@haypocalc.com>
date Tue, 05 Jul 2011 14:00:56 +0200
parents 52c5f80122dd
children 807921ba241d 42e23db3ddfc
line wrap: on
line diff
--- a/Lib/test/test_subprocess.py	Tue Jul 05 11:31:49 2011 +0200
+++ b/Lib/test/test_subprocess.py	Tue Jul 05 14:00:56 2011 +0200
@@ -675,6 +675,22 @@
         time.sleep(2)
         p.communicate(b"x" * 2**20)
 
+    def test_communicate_eintr(self):
+        # Issue #12493: communicate() should handle EINTR
+        def handler(signum, frame):
+            pass
+        old_handler = signal.signal(signal.SIGALRM, handler)
+        self.addCleanup(signal.signal, signal.SIGALRM, old_handler)
+
+        # the process is running for 2 seconds
+        args = [sys.executable, "-c", 'import time; time.sleep(2)']
+        for stream in ('stdout', 'stderr'):
+            kw = {stream: subprocess.PIPE}
+            with subprocess.Popen(args, **kw) as process:
+                signal.alarm(1)
+                # communicate() will be interrupted by SIGALRM
+                process.communicate()
+
 
 # context manager
 class _SuppressCoreFiles(object):