Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python sched alternative to cancel all events

Tags:

python

events

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

like image 244
Toni Avatar asked Dec 17 '22 04:12

Toni


1 Answers

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

like image 50
iamamac Avatar answered Jan 09 '23 00:01

iamamac