Python – Kill Python Multiprocessing Pool

linuxmultiprocessingpython

I am running a Python program which uses the multiprocessing module to spawn some worker threads. Using Pool.map these digest a list of files.

At some point, I would like to stop everything and have the script die.

Normally Ctrl+C from the command line accomplishes this. But, in this instance, I think that just interrupts one of the workers and that a new worker is spawned.

So, I end up running ps aux | grep -i python and using kill -9 on the process ids in question.

Is there a better way to have the interrupt signal bring everything to a grinding halt?

Best Answer

SIGQUIT (Ctrl + \) will kill all processes even under Python 2.x.

You can also update to Python 3.x, where this behavior (only child gets the signal) seems to have been fixed.