multiprocessing and SIGINT
akineko at gmail.com
Fri Jan 9 06:04:58 CET 2009
It is a bit awkward to respond to my posting but I have some updates.
I created two simple test programs, one uses threading and another
What I found was:
(1) test program with threading
Only main thread receives SIGINT (generated thread won't receive
(2) test program with multiprocessing
Both processes receives SIGINT.
OS apparently distributes the SIGINT event to processes associated
with the terminal.
(3) signal handler
I realized that I could assign a signal handler specific to a process
by placing it to a worker method.
# this process ignores SIGINT
... the rest ...
process = multiprocessing.Process(target=worker)
(4) terminating the spawned process
I needed to send a shutdown message to the process via a communication
between two processes.
You can use Process.terminate() to brutally kill the process but that
is a last resort.
Now my program can shutdown elegantly when I type Ctrl-C.
I see a big potential in multiprocessing as more PCs now have multi-
More information about the Python-list