Signal handler, python
I have a multithreaded program and use the signal.signal(SIGINT,func) to kill all threads when ctrl c is pressed. The question I have is this:
I have to call signal.si开发者_开发技巧gnal(...) from main in python. Do I have to call that on a loop or can I just set it once and whenever the user presses ctrl c, the signal will be caught?
Only the main tread can handle signals. Just make all your threads "daemonic" ones (set the thread object's .daemon
property to True
before you start the thread) to ensure the threads terminate when the main thread does.
精彩评论