os.popen() interferes with os.fork()?

JohnMudd JohnBMudd at gmail.com
Mon Aug 25 14:50:07 EDT 2008


On Linux I get a "close failed: [Errno 10] No child processes" msg for
each fork.  But only if I have a pipe open.  I don't understand the
connection between the popen and the forks.  Am I doing something
wrong?


#! /usr/bin/env python

import os
import sys
import time

p = os.popen('top -b -d1')

n = 3
t1 = time.time()
for i in range(n):
  pid = os.fork()
  if pid == 0:
    sys.exit(0)
delay = time.time() - t1
print 'rate: %.1f fork/sec' % (n/delay)



More information about the Python-list mailing list