apfejes/epigenetics-software — pull request #6 by dfornika (2013-04-02 21:19:16+00:00)
Title: Implemented 'poison pill' method for interrupting multiprocess queue

I'll caution you to test this one before merging it, or even just take a look at it and do your own thing.

This fix is based on this stackoverflow answer.

http://stackoverflow.com/a/7829756

Essentially, when ctrl-c is pressed, the child processes catches and ignores the KeyboardInterrupt. The main process now catches the KeyboardInterrupt and adds a "poison pill" in the form of the string "exit" to the map_queue. The sub-process checks for the "poison pill" and exits when it is detected.

Note that on line 247 of MapDecomposingThread.py there is space for further clean-up code, that I've likely overlooked.

I added a little extra logging output so you can see the map_queue emptying when the program is interrupted.

The "poison pill" method is also referenced here:

http://pymotw.com/2/multiprocessing/basics.html#terminating-processes