Possible Duplicate:
Keyboard Interrupts with python's multiprocessing Pool
Python's multiprocessing module has something called Pool http://docs.python.org/library/multiprocessing.html#module-multiprocessing.pool
While a pool of processes is operating, I can't get the script to terminate using KeyboardInterrupt i.e Ctrl + c. The pool spawns new processes and the only way to get out is ctrl + z followed by killing them manually.
Here is the script that I tried to test it on:
import multiprocessing
import random
import time
def sometask(arg):
#do something nasty to arg
time.sleep(arg)
return random.randint(0,arg)
if __name__=="__main__":
pool = multiprocessing.Pool(processes=4)
print pool.map(sometask, range(10))
My main script tries to do something that is much more time consuming than time.sleep() and every time I try to test run it, I have to wait for it to finish or kill it manually by first finding the id of the processes it spawned. Please suggest a work around.