Python线程。计时器有时会停止、暂停或冻结
我的代码总结如下Python线程。计时器有时会停止、暂停或冻结,python,python-3.x,timer,python-multithreading,Python,Python 3.x,Timer,Python Multithreading,我的代码总结如下 import threading import time def checkMinute(num): print('check ' + str(num)) print(str(num) + ' work start') # other python code.... print(str(num) + ' work end') startTimer(num) def startTimer(num): t = threading.
import threading
import time
def checkMinute(num):
print('check ' + str(num))
print(str(num) + ' work start')
# other python code....
print(str(num) + ' work end')
startTimer(num)
def startTimer(num):
t = threading.Timer(10, checkMinute, args=(num,))
t.daemon = True
t.start()
if __name__== '__main__':
startTimer(1)
startTimer(2)
startTimer(3)
time.sleep(1000)
它必须在键盘插入之前继续工作
但有时,我不知道该怎么说,但它会停止、暂停或冻结
例如,控制台日志如下
# 10am in real time. program is start
2021-04-21 10:00:00 : check 1
2021-04-21 10:00:00 : 1 work start
2021-04-21 10:00:00 : check 2
2021-04-21 10:00:00 : 2 work start
2021-04-21 10:00:00 : check 3
2021-04-21 10:00:00 : 3 work start
2021-04-21 10:00:13 : 1 work end
2021-04-21 10:00:20 : 2 work end
2021-04-21 10:00:21 : 3 work end
# I want continue it
# but sometimes
2021-04-21 17:10:21 : 3 work end
# Next, 'check 1' and '1 work start' have to progress
# But the real time is 9pm, but no progress has been made since the program stopped at 5pm.
# When I input enter on command window, It work again with no error
为什么会这样?
我怎样才能修好它
python版本是3.6