How can I stop or reach to avoid hanging of the following:
如何停止或触及以避免挂起以下内容:
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
Somehow the input should be stopped, time outted, killed, anything..
不知何故,输入应该停止,时间浪费,杀死,任何东西..
1 个解决方案
#1
0
Solved with setting the thread to daemon: mythread.daemon = True mythread.start()
通过将线程设置为守护进程解决:mythread.daemon = True mythread.start()
#1
0
Solved with setting the thread to daemon: mythread.daemon = True mythread.start()
通过将线程设置为守护进程解决:mythread.daemon = True mythread.start()