Red Hat Bugzilla – Bug 1073165
subprocess.Popen.communicate() fails with: IOError: [Errno 4] Interrupted system call
Last modified: 2016-04-18 06:17:01 EDT
Description of problem: Popen.communicate() raises IOError when the underlying read fails with EINTR due to a signal handler firing. It only happens when one of stdout or stderr is piped (therefore a possible workaround is to pipe both stdout and stderr and ignore the one that is not needed). We see this intermittently in our Beaker self-test suite, where we execute lsof and read its stdout. Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/nose/suite.py", line 208, in run self.setUp() File "/usr/lib/python2.6/site-packages/nose/suite.py", line 291, in setUp self.setupContext(ancestor) File "/usr/lib/python2.6/site-packages/nose/suite.py", line 314, in setupContext try_run(context, names) File "/usr/lib/python2.6/site-packages/nose/util.py", line 469, in try_run return func() File "/usr/lib/python2.6/site-packages/bkr/inttest/__init__.py", line 337, in setup_package process.start() File "/usr/lib/python2.6/site-packages/bkr/inttest/__init__.py", line 148, in start self._wait_for_listen(self.listen_port) File "/usr/lib/python2.6/site-packages/bkr/inttest/__init__.py", line 158, in _wait_for_listen if check_listen(self.listen_port): File "/usr/lib/python2.6/site-packages/bkr/inttest/__init__.py", line 109, in check_listen stdout=subprocess.PIPE).communicate() File "/usr/lib64/python2.6/subprocess.py", line 723, in communicate stdout = self.stdout.read() IOError: [Errno 4] Interrupted system call The upstream bug is: http://bugs.python.org/issue12493 Fixed upstream in Python 2.7: http://hg.python.org/cpython/rev/6a28ccde2f1b Version-Release number of selected component (if applicable): python-2.6.6-52.el6.x86_64 How reproducible: easily Steps to Reproduce: The upstream test suite has a reliable reproducer, here is an example based on that: Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess, sys, signal >>> def handler(signum, frame): pass ... >>> signal.signal(signal.SIGALRM, handler) 0 >>> p = subprocess.Popen('sleep 20', shell=True, stdout=subprocess.PIPE) >>> signal.alarm(1) ; p.communicate() 0 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib64/python2.6/subprocess.py", line 723, in communicate stdout = self.stdout.read() IOError: [Errno 4] Interrupted system call >>> Actual results: Popen.communicate() call raises IOError due to EINTR. Expected results: Popen.communicate() should retry after EINTR and successfully return a result. Additional info: Looks related to bug 1065537 (probably the upstream patch for this bug depends on that one).
devel_ack+, we can fix this with the referenced patch.
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://rhn.redhat.com/errata/RHSA-2015-1330.html