Signal Handler, python

I have a multi-threaded program and use signal.signal (SIGINT, func) to kill all threads when I press ctrl c. I have a question:

I need to call signal.signal (...) from main in python. Should I call it in a loop, or can I just set it once and whenever the user press ctrl c, will the signal be caught?

+4
source share
1 answer

Only the main protector can handle signals. Just make all your daemonic threads (set the .daemon thread .daemon to True before the thread starts) to ensure that the threads terminate when the main thread is running.

+2
source

All Articles