Will this finally let me write a parallel Python script that doesn't explode when I press control+C?
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL)
Now it will just die on Ctrl-C. For text filter programs it's a good idea to do the same for SIGPIPE too.If you want the child processes to shutdown when the main process goes down, you should be able to just set .daemon = True on the process objects before you start them.
If you want exceptions in the children thread to propagate up to the main thread and then handle, looks like you'd just need to send the exception across a queue or something in multiproccessing. In the new futures library, your future (wrapping the process) has a return value property you can try to access. If the child process ran into an exception, that exception would be raised in the main process when you tried to access that return value.
Or did I misunderstand the problem?
with ThreadPool() as pool:
fut = pool.submit(foo)
print(fut.result())
My idea is that ctrl+c would now cancel child operations cleanly?