Python KeyboardInterrupt in Multithreading

橙三吉。 提交于 2019-12-08 05:30:32

First, your instance myThread in created with error, must be stopper=stopper (keyword arg is expected). Second, code has error, main thread does not wait server thread but immediately go to join()s. So, except never happens - nothing will be printed. And main bug is in join(). Join in Python is not interruptable by signals. So, you must write own join function, which will call original join() with timeout (for example, 1 second) but in the infinitive loop. Better is to make join with little timeout and next - sleep() - sleep is interruptable. Both in the loop.

Try to print something next of except KeyboardInterrupt, before to call join()s, bcz joins are waiting for threads to complete.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!