Skip to content

Instantly share code, notes, and snippets.

@wenboown
Created December 5, 2018 05:09
Show Gist options
  • Select an option

  • Save wenboown/1bc3f2843e0f503ea3f0c25177110fd8 to your computer and use it in GitHub Desktop.

Select an option

Save wenboown/1bc3f2843e0f503ea3f0c25177110fd8 to your computer and use it in GitHub Desktop.
run sched function in a separate thread so that new event can be pushed into the queue, will quite when the queue becomes empty
import sched, time
from threading import Thread
def print_time(a='default'):
print("From print_time", time.time(), a)
s = sched.scheduler(time.time, time.sleep)
s.enterabs(time.time()+1, 0, print_time, argument=('before',))
def start():
print('start')
s.run()
t = Thread(target=start)
t.start()
for i in range(10):
s.enterabs(time.time() + i, 1, print_time, argument=('item '+str(i),))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment