Exiting a multiprocess python application is safe

I noticed that os._exit(<num>) ::

Quit a process with status n without calling cleanup handlers, flushing stdio buffers, etc.

and what sys.exit() ::

"only" throws an exception, it will exit the process only when called from the main thread

I need a solution for closing a multiprocessor application, which ensures that all processes will be closed (none of those left without orphans), and that it will exit in the best condition.

Additionally:

I create processes using the python multiprocessing library, creating classes that inherit from multiprocessing.Process

+4
source share
1 answer

I ended up creating a Pipe for each process. Then, when the main process shuts down, it can send a message to all child processes, which they must also close.

To make this work right, you should periodically check the "Processes" processes of the child processes for "Processes" to see if there are messages in the channel, and if so, check them, quit now ".

+1
source

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


All Articles