Created
December 5, 2018 05:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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