我有这个非常简单的代码来在后台启动计划任务,但没有打印任何内容:
def printit():
print("Hello, World!")
scheduler = sched.scheduler(time.time, time.sleep)
scheduler.enter(2, 1, printit)
scheduler.run(blocking=False)
while True:
time.sleep(1)
如果我将阻塞设置为 true,它就会起作用。有什么想法吗?
最佳答案
您没有将调度事件的控制权交给调度程序。稍后尝试运行。
def printit():
print("Hello, World!")
scheduler = sched.scheduler(time.time, time.sleep)
scheduler.enter(2, 1, printit)
while True:
time.sleep(1) # optional to prevent thrash
scheduler.run(blocking=False)
关于python - 为什么调度函数从未被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34409425/