Multiprocessing Process terminate fails on Linux Multiprocessing Process terminate fails on Linux linux linux

Multiprocessing Process terminate fails on Linux


From the docs:

terminate()

Terminate the process. On Unix this is done using the SIGTERM signal; on Windows TerminateProcess() is used. Note that exit handlers and finally clauses, etc., will not be executed.

Note that descendant processes of the process will not be terminated – they will simply become orphaned.

So it looks like you have to make sure that your process handles the SIGTERM signal correctly.

Use signal.signal to set a signal handler.

To set a SIGTERM signal handler that simply exist the process, use:

import signalimport syssignal.signal(signal.SIGTERM, lambda signum, stack_frame: sys.exit(1))

EDIT

A Python process normally terminates on SIGTERM, I don't know why your multiprocessing process doesn't terminate on SIGTERM.


Not exactly a direct answer to your question, but since you are dealing with the threads this could be helpful as well for debugging those threads: https://stackoverflow.com/a/10165776/1019572I recently found a bug in cherrypy using this code.