Interrupting Python raw_input() in a child thread with ^C/KeyboardInterrupt

前端 未结 2 1458
遥遥无期
遥遥无期 2021-01-18 01:17

In a multithreaded Python program, one thread sometimes asks for console input using the built-in raw_input(). I\'d like to be able to be able to close the program while at

2条回答
  •  遥遥无期
    2021-01-18 01:28

    When join is called with no timeout, it is uninterruptable, but when it is called with a timeout, it is interruptable. Try adding an arbitrary timeout and putting it in a while loop:

    while my_thread.isAlive():
        my_thread.join(5.0)
    

提交回复
热议问题