Python Multiprocessing respawn splits processes

I want to create some workflows, and if they happen due to an exception, I would like them to revive. Other than the is_alive method in the multiprocessing module, I cannot find a way to do this.

This will require me to repeat all running processes (after sleep) and check if they are alive. This is essentially a busy cycle, I was wondering if there is a better solution that will awaken my program if any of my work processes crashed. As soon as it wakes up, I would like to catch an exception that crashed my program and started another process.

+4
source share
3 answers

A poll to check if the child processes are alive is working fine, as this is a small premium and you don't need to check it often.

The first answer to this (similar) question contains an example of Python code: Multi-server monitor / auto repair in python

+2
source

You can wrap your workflows in try / except blocks, where an exception pushes the message to the pipe before assembly. Of course, the survey is really no worse than this, and it's easier.

+1
source

If you are using a Unix-like system, your main program can be notified of dead children by installing a signal handler . Check your operating system documentation for signal() , especially SIGCHLD . I'm afraid I don't remember if Windows covers SIGCHLD with very limited POSIX signal support.

+1
source

Source: https://habr.com/ru/post/1337550/


All Articles