diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/subprocess.py | 6 | ||||
-rw-r--r-- | Lib/test/test_subprocess.py | 16 |
2 files changed, 19 insertions, 3 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index cfd4c85..83e6c40 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -446,7 +446,7 @@ def _eintr_retry_call(func, *args): while True: try: return func(*args) - except OSError as e: + except (OSError, IOError) as e: if e.errno == errno.EINTR: continue raise @@ -820,10 +820,10 @@ class Popen(object): raise self.stdin.close() elif self.stdout: - stdout = self.stdout.read() + stdout = _eintr_retry_call(self.stdout.read) self.stdout.close() elif self.stderr: - stderr = self.stderr.read() + stderr = _eintr_retry_call(self.stderr.read) self.stderr.close() self.wait() else: diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py index 6e31fe7..15d83e7 100644 --- a/Lib/test/test_subprocess.py +++ b/Lib/test/test_subprocess.py @@ -767,6 +767,22 @@ class ProcessTestCase(BaseTestCase): 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): |