DeaD_EyE

scheduler example with datetime and dateutil

Jul 30th, 2020
1,533
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sched
  2. import time
  3. import datetime
  4. from dateutil.rrule import rrule, HOURLY, MINUTELY
  5.  
  6.  
  7. def schdule(start, end, interval=2):
  8.     scheduler = sched.scheduler(timefunc=time.time)
  9.     now = datetime.datetime.now().replace(second=0, microsecond=0) + datetime.timedelta(minutes=1)
  10.     for future in rrule(freq=MINUTELY, interval=interval, dtstart=now):
  11.         scheduler.enterabs(future.timestamp(), 0, lambda *args, **kwargs: print(datetime.datetime.now()))
  12.         scheduler.run()
RAW Paste Data