SIGCHLD signal handling
olaf.meyer at nokia.com
Mon Sep 4 15:14:02 CEST 2000
thanks a lot. Your code does the trick :-)
Do you have any idea why the
is interrupted by the signal handler?
Oleg Broytmann wrote:
> On Mon, 4 Sep 2000, Olaf Meyer wrote:
> > I'm having some problems with the SIGCHLD signal on HP-UX 11.
> From c.evans at clear.net.nz Wed Jun 9 15:51:57 1999
> Date: 09 Jun 1999 23:26:47 +1200
> From: Carey Evans <c.evans at clear.net.nz>
> To: python-list at python.org
> Newsgroups: comp.lang.python
> Subject: Re: waste of resources ?
> 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..."
> while 1:
> pid, sts = os.waitpid(-1, os.WNOHANG)
> if pid == 0:
> print "Process %d ended with status %04x." % (pid, sts)
> except OSError, detail:
> if detail.args != errno.ECHILD:
> print "No more children."
> 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 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