I'm looking for an alternative to the sched module which would allow me to cancel all events at any time. sched only allows to cancel single events by id (which is returned from the scheduler when an event is scheduled). Any pointers to Python alternatives to sched would be appreciated. Thanks Toni p
In python 2.6, there is a read-only attribute called queue
returning a list of upcoming events. So this will cancel all events:
s = sched.scheduler(time.time, time.sleep)
map(s.cancel, s.queue)
Update for Python 3:
Python 3 map() returns the iterator. Therefore, the object must be converted to the list.
s = sched.scheduler (time.time, time.sleep)
list(map(s.cancel, s.queue))
Check out https://stackoverflow.com/a/1303354/6523409 and https://stackoverflow.com/a/13623676/6523409
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With