bugs.python.org

Issue686667

Created on 2003-02-14 17:47 by bernhard, last changed 2022-04-10 16:06 by admin. This issue is now closed.

Messages (4)
msg60310 - (view) Author: Bernhard Herzog (bernhard) Date: 2003-02-14 17:47
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
msg60311 - (view) Author: Mark McLoughlin (markmc) Date: 2005-05-09 12:07
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
msg60312 - (view) Author: David Hess (david_k_hess) Date: 2006-01-30 01:30
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):
msg63058 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2008-02-27 02:28
spawnv is deprecated, use sobprocess instead.
And please, if you say to find the same issue in subprocess, provide a
test case to check what you say.
Thanks!!
History
Date User Action Args
2022-04-10 16:06:49adminsetgithub: 37988
2008-02-27 02:28:59facundobatistasetstatus: open -> closed
nosy: + facundobatista
resolution: out of date
messages: + msg63058
2003-02-14 17:47:18bernhardcreate

Read the original on bugs.python.org ↗