I have following test code executed on Windows:
import multiprocessing
import time
def child() :
while True :
time.sleep( 2 )
if __name__ == '__main__' :
multiprocessing.Process( target = child ).start()
while True :
time.sleep( 1 )
If i press Ctrl-C while it's working, i see two KeyboardInterrupt exceptions - one for sleep( 1 ) and one for sleep( 2 ). How it's happens that keyboard interrupt in main process is forwarded to child process? They are processes after all, not threads :(.
The KeyboardInterrupt exception is thrown when a process catches the SIGINT signal which indicates a keyboard interrupt (pressing ctrl+c).
In Unix/Linux systems the SIGINT signal is sent to the entire foreground process group which includes the parent process and its child processes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With