[ python-Bugs-686667 ] os.spawnv(P_WAIT, ...) on Linux doesn't handle EINTR

SourceForge.net noreply at sourceforge.net
Mon Jan 30 02:30:28 CET 2006


Bugs item #686667, was opened at 2003-02-14 11:47
Message generated for change (Comment added) made by david_k_hess
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=686667&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Bernhard Herzog (bernhard)
Assigned to: Nobody/Anonymous (nobody)
Summary: os.spawnv(P_WAIT, ...) on Linux doesn't handle EINTR

Initial Comment:
The implementation of os.spawnv when called with the
P_WAIT flag calls waitpid to wait for the subprocess.
If this function is aborted early because of a signal,
i.e. if it raises OSError with EINTR, it should be
called again.

I ran across this bug when trying to write a test case
for a script that stops another process. Both the
script and the other process are executed as
subprocesses of the test program. The stop script is
executed with os.spawnv(P_WAIT,  ...) to wait until the
script completed. Unfortunately when it stops the other
process a SIGCHLD is sent to the test program which
then aborts the waitpid with an exception.

Tested with Python 2.1.3, 2.2 and CVS from 2003-02-13
Platform: Debian GNU/Linux, Kernel 2.4.20

----------------------------------------------------------------------

Comment By: David Hess (david_k_hess)
Date: 2006-01-29 19:30

Message:
Logged In: YES 
user_id=896179

Also seen on Mac OS X 10.4.4 (Darwin 8.4.0) with Python 2.4.2.

The Zope guys are seeing it too:

http://mail.zope.org/pipermail/zope-collector-monitor/2005-December/
006267.html

It seems remarkable that this bug has been open for 3 years. spawn*() are 
pretty much useless without a fix.

Here's patch that works for me:

--- /Users/dhess/os.py  2006-01-29 19:29:25.000000000 -0600
+++ /opt/local/Library/Frameworks/Python.framework/Versions/2.4/lib/
python2.4/os.py     2006-01-29 19:29:32.000000000 -0600
@@ -532,7 +532,13 @@
             if mode == P_NOWAIT:
                 return pid # Caller is responsible for waiting!
             while 1:
-                wpid, sts = waitpid(pid, 0)
+                try:
+                    wpid, sts = waitpid(pid, 0)
+                except OSError, exc:
+                    import errno
+                    if exc.errno == errno.EINTR:
+                        continue
+                    raise
                 if WIFSTOPPED(sts):
                     continue
                 elif WIFSIGNALED(sts):



----------------------------------------------------------------------

Comment By: Mark Mc Loughlin (markmc)
Date: 2005-05-09 07:07

Message:
Logged In: YES 
user_id=116392

Seeing this on Ubuntu with Sabayon
(www.gnome.org/projects/sabayon):

  http://bugzilla.gnome.org/show_bug.cgi?id=303034

Python version is 2.4.1

This is particularily painful because there's no way to get
the PID of the process which waitpid was wating on when it
was interrupted, so there's no way to reap the child

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=686667&group_id=5470


More information about the Python-bugs-list mailing list