Reputation: 380
I have this very simple code to initiate a scheduled task in the background but nothing gets printed:
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)
It works if I set blocking to true. Any ideas?
Upvotes: 1
Views: 578
Reputation: 1804
You aren't giving the scheduler back control to schedule events. Try running at a later time.
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)
Upvotes: 1