classification
Title: subprocess raising "No Child Process" OSError
Type: Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: duplicate
Dependencies: Superseder: race condition in subprocess module
View: 1731717
Assigned To: Nosy List: abo, georg.brandl, slowfood
Priority: normal Keywords:

Created on 2007-07-14 03:06 by slowfood, last changed 2010-03-04 22:49 by flox. This issue is now closed.

Files
File name Uploaded Description Edit
subprocess_noChildErr.py slowfood, 2007-07-14 03:06 Subprocess OSError on multiple CPU's
Messages (5)
msg32505 - (view) Author: slowfood (slowfood) Date: 2007-07-14 03:06
The program below demostrates a "No Child Process" OSError on a multi-cpu systems.

This is extracted from a large system where we
are trying to manage many sub-processes,
some of which end up having little/no real work to
do so they return very fast, here emulated by
having the sub-process be an invocation of:
  Executable="/bin/sleep 0"

Seems like some race condition, since if you make the
child process take some time (sleep 0.1) the frequency
of errors decreeses.
Error only shows up when there are more threads than 
have real CPU's by at least a factor of two, on dual core machines up NumThreads to 18 to get the failures.

Same error on both Python 2.4.3 with:
 Linux 2.6.18-gentoo-r3  Gentoo 
and Python 2.4.4 with:
 Linux 2.6.20-gentoo-r8

Any help appreciated -

= = = ===== Start code example ===========

% python subprocess_noChildErr.py
Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib64/python2.4/threading.py", line 442, in __bootstrap
    self.run()
  File "testCaseA.py", line 14, in run
    subprocess.call(Executable.split())
  File "/usr/lib64/python2.4/subprocess.py", line 413, in call
    return Popen(*args, **kwargs).wait()
  File "/usr/lib64/python2.4/subprocess.py", line 1007, in wait
    pid, sts = os.waitpid(self.pid, 0)
OSError: [Errno 10] No child processes

Test finished
% cat subprocess_noChildErr.py
import subprocess, threading

# Params
Executable="/bin/sleep 0"
NumThreads = 18
NumIterations = 10

class TestClass(threading.Thread):
   def __init__(self, threadNum):
       self.threadNum = threadNum
       threading.Thread.__init__(self)
   def run(self):
       for i in range(NumIterations):
           subprocess.call(Executable.split())

def test():
   allThreads = []
   for i in range(NumThreads):
       allThreads.append(TestClass(i))
   for i in range(NumThreads):
       allThreads[i].start()
   for i in range(NumThreads):
       allThreads[i].join()
   print "Test finished"

if __name__ == '__main__':
   test()


% python -V
Python 2.4.4
% uname -a
Linux 2.6.20-gentoo-r8 #2 SMP PREEMPT Sun Jul 1 13:22:56 PDT 2007 x86_64 Dual-Core AMD Opteron(tm) Processor 2212 AuthenticAMD GNU/Linux
%
% date
Fri Jul 13 19:26:44 PDT 2007
%

= = = ===== End code example ===========


msg32506 - (view) Author: Donovan Baarda (abo) * Date: 2007-08-03 19:37
Bugs 1754642 and 1753891 both look like duplicates of bug 1731717 to me. I suggest marking them both as dups of 1731717 because that one has info on the race-condition that causes this and discussions on how to fix it.
msg32507 - (view) Author: slowfood (slowfood) Date: 2007-08-03 20:01
I agree with abo that this looks to be a dup of 1731717, will try to mark it as such.
msg32508 - (view) Author: slowfood (slowfood) Date: 2007-08-03 20:07
Managed to mark it as a duplicate, but not able to tie it to 1731717.
Sorry -
;;slowfood
msg32509 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2007-08-04 07:25
Closing too. Tying bugs is not supported by SF.
History
Date User Action Args
2010-03-04 22:49:01floxsetsuperseder: race condition in subprocess module
2007-07-14 03:06:15slowfoodcreate