python线程如何捕获中断信号
如题,当按下Ctrl+C时,我希望能够在线程内捕获到该信号,并结束本线程,请问该怎么实现。
[解决办法]
用except捕获KeyboardInterrupt
[解决办法]
同ls。
python 使用
try:
except
处理和捕获异常,
[解决办法]
貌似得在主线程里做...
18.5. signal — Set handlers for asynchronous events
...
18.5.1.2. Signals and threads
Python signal handlers are always executed in the main Python thread, even if the signal was received in another thread. This means that signals can’t be used as a means of inter-thread communication. You can use the synchronization primitives from the threading module instead.
Besides, only the main thread is allowed to set a new signal handler.