mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
(merge 3.2) Issue #12493: subprocess: communicate() handles EINTR
subprocess.Popen.communicate() now also handles EINTR errors if the process has only one pipe.
This commit is contained in:
commit
5b1261d750
3 changed files with 22 additions and 3 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue