python线程怎么捕获中断信号


        python线程如何捕获中断信号<br />

如题,当按下Ctrl+C时,我希望能够在线程内捕获到该信号,并结束本线程,请问该怎么实现。

perl 程序开发 Perl语言基础

我不是葛炮 9 years, 11 months ago

貌似得在主线程里做...


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.


射得满满的 answered 9 years, 11 months ago

同ls。

python 使用

try:

except

处理和捕获异常,

eonshow answered 9 years, 11 months ago

用except捕获KeyboardInterrupt

Ex星☆羽 answered 9 years, 11 months ago

Your Answer