changeset: 71229:42e23db3ddfc parent: 71225:e8646f120330 parent: 71228:dcfacc2d93b4 user: Victor Stinner date: Tue Jul 05 14:04:39 2011 +0200 files: Lib/subprocess.py Lib/test/test_subprocess.py Misc/NEWS description: (merge 3.2) Issue #12493: subprocess: communicate() handles EINTR subprocess.Popen.communicate() now also handles EINTR errors if the process has only one pipe. diff -r e8646f120330 -r 42e23db3ddfc Lib/subprocess.py --- a/Lib/subprocess.py Tue Jul 05 11:34:18 2011 +0200 +++ b/Lib/subprocess.py Tue Jul 05 14:04:39 2011 +0200 @@ -446,7 +446,7 @@ 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 @@ 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 -r e8646f120330 -r 42e23db3ddfc Lib/test/test_subprocess.py --- a/Lib/test/test_subprocess.py Tue Jul 05 11:34:18 2011 +0200 +++ b/Lib/test/test_subprocess.py Tue Jul 05 14:04:39 2011 +0200 @@ -767,6 +767,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): diff -r e8646f120330 -r 42e23db3ddfc Misc/NEWS --- a/Misc/NEWS Tue Jul 05 11:34:18 2011 +0200 +++ b/Misc/NEWS Tue Jul 05 14:04:39 2011 +0200 @@ -219,6 +219,9 @@ Library ------- +- Issue #12493: subprocess: Popen.communicate() now also handles EINTR errors + if the process has only one pipe. + - Issue #12467: warnings: fix a race condition if a warning is emitted at shutdown, if globals()['__file__'] is None.

AltStyle によって変換されたページ (->オリジナル) /