In my class I run 4 process.
from multiprocessing import Process
procs = (
Process(target=ClassOne, name='ClassOne'),
Process(target=ClassTwo, name='ClassTwo'),
Process(target=ClassThree, name='ClassThree'),
Process(target=ClassFour, name='ClassFour'),
)
for p in procs:
p.daemon = False
p.start()
I would like to be notified when one of my children process died so i can kill the other and my self.
Just define a signal handler for SIGCHLD, inspect the frame returned by the just dead child to retrieve the information you need about it ... and if necessary exit() the parent too :)
It is possible to use os.waitpid()
passing -1 as the first argument and 0 as the second one.
wait()
. The function returns a tuple with the pid of the dead child and its exit code.
You might like to look at the class AutoJoiningProcess in the answer to this similar question.
If you're prepared to add to your code a dependency to gobject (part of PyGTK) then AutoJoiningProcess would allow you can listen to a signal that is emitted when a process finishes. On that signal you could then respond however you'd like.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With