waste of resources ?

Carey Evans c.evans at clear.net.nz
Wed Jun 9 07:26:47 EDT 1999


Unix doesn't guarantee you'll get exactly one signal delivered per
event.  To be sure to get all the children, you need to loop over the
processes with waitpid().

I think something like this should do it:

----------
def sigchld_handler(signum, frame):
    print "Checking for processes..."
    try:
        while 1:
            pid, sts = os.waitpid(-1, os.WNOHANG)
            if pid == 0:
                break
            print "Process %d ended with status %04x." % (pid, sts)
    except OSError, detail:
        if detail.args[0] != errno.ECHILD:
            raise
        else:
            print "No more children."
    else:
        print "Some children yet to finish."
----------

I can't actually see any way to keep count well enough and avoid race
conditions, to get rid of the try/except.  Sometimes I wish Python had 
POSIX signals, but not badly enough to actually write it.

-- 
	 Carey Evans  http://home.clear.net.nz/pages/c.evans/

	     "I'm not a god.  I've just been misquoted."

Oleg.
---- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list