Keyboard Interrupt in Python Using ThreadPool

2014-03-12 | #python, #solution

If you are one of the brave ones, using Python2's highly undocumented, but extremely comfy multithreading.pool.ThreadPool you might experience some problems terminating a script like this via KeyboardInterrupt.

To make it short:

KeyboardInterrupt excepts won't work.

SIGINT-signal-handling won't work.

What will work however, even if this can be considered lazy and dirty is pausing the process with CTRL-Z, which will pause the script and print the job ID as "[1]+ ...." in the brackets at the start of the output.

You can now terminate this job manually and check it's status afterwards:

kill %1 && fg