This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kjd@duda.org
Recipients kjd@duda.org
Date 2007-10-04.21:31:55
SpamBayes Score 0.09154025
Marked as misclassified No
Message-id <1191533517.74.0.548071476021.issue1236@psf.upfronthosting.co.za>
In-reply-to
Content
The following test program crashes:

========================================
import threading, sys, subprocess

# subprocess._cleanup = lambda: None

def doit():
   for i in xrange(0, 1000):
      p = subprocess.Popen( "true" )
      p.wait()

t = threading.Thread( target=doit )
t.start()
doit()

==============================

It crashes because when one thread calls subprocess.Popen(), subprocess
calls this _cleanup() function, which might reap the subprocess started
in another thread !  The other thread might be inside
subprocess.Popen.wait(), just about to call waitpid(), and kill itself.

If you uncomment the commented line, then the program runs with no problems.

I imagine the purpose of _cleanup is to protect users from themselves,
i.e., protect a user who calls subprocess.Popen() a lot without ever
calling wait().  I suggest either:

  (1) eliminating this _cleanup() mechanism completely; people who do
not wait() deserve the zombies they get;
  (2) synchronizing _cleanup() with wait() through a lock; or,
  (3) having wait() simply retry if it gets ECHILD.  On the retry, it
will discover that returncode is set, and return normally.

-Ken
History
Date User Action Args
2007-10-04 21:31:58kjd@duda.orgsetspambayes_score: 0.0915402 -> 0.09154025
recipients: + kjd@duda.org
2007-10-04 21:31:57kjd@duda.orgsetspambayes_score: 0.0915402 -> 0.0915402
messageid: <1191533517.74.0.548071476021.issue1236@psf.upfronthosting.co.za>
2007-10-04 21:31:57kjd@duda.orglinkissue1236 messages
2007-10-04 21:31:56kjd@duda.orgcreate