如何停止或伸手避免悬挂以下物品:
import threading
mythread = Threading(target = input_read, args = (callback))
mythread.start()
running = True
def callback(msg):
if msg == 'stop': running = False
print(msg)
def input_read(callback):
while running:
callback(input())
while running:
try:
# some other code
except KeyboardInterrupt:
pass
应该以某种方式停止输入,超时,终止输入等。
答案 0 :(得分:0)
解决了将线程设置为守护程序的问题: mythread.daemon =真 mythread.start()