Missing SIGCHLD

Dinh pcdinh at gmail.com
Tue Feb 15 05:57:09 EST 2011


Hi,

I currently build a process management system which is able to fork child
processes (fork()) and keep them alive (waitpid() ).

             if pid in self.current_workers:
                 os.waitpid(pid, 0)

If a child process dies, it should trigger a SIGCHLD signal and a handler is
installed to catch the signal and start a new child process. The code is
nothing special, just can be seen in any Python tutorial you can find on the
net.

            signal.signal(signal.SIGCHLD, self.restart_child_process)
            signal.signal(signal.SIGHUP, self.handle) # reload
            signal.signal(signal.SIGINT, self.handle)
            signal.signal(signal.SIGTERM, self.handle)
            signal.signal(signal.SIGQUIT, self.handle)

However, this code does not always work as expected. Most of the time, it
works. When a child process exits, the master process receives a SIGCHLD and
restart_child_process() method is invoked automatically to start a new child
process. But the problem is that sometimes, I know a child process exits due
to an unexpected exception (via log file) but it seems that master process
does not know about it. No SIGCHLD and so restart_child_process() is not
triggered. Therefore, no new child process is forked.

Could you please kindly tell me why this happens? Is there any special code
that need being installed to ensure that every dead child will be informed
correctly?

Mac OSX 10.6
Python 2.6.6

Thanks


Dinh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110215/609a9dd4/attachment.html>


More information about the Python-list mailing list