Event Priorities

If more than one event is scheduled for the same time their priority values are used to determine the order they are run.

import sched
import time

scheduler = sched.scheduler(time.time, time.sleep)

def print_event(name):
    print 'EVENT:', time.time(), name

now = time.time()
print 'START:', now
scheduler.enterabs(now+2, 2, print_event, ('first',))
scheduler.enterabs(now+2, 1, print_event, ('second',))

scheduler.run()

 

This example needs to ensure that they are scheduled for the exact same time, so the enterabs() method is used instead of enter(). The first argument to enterabs() is the time to run the event, instead of the amount of time to delay. The second argument is the priority value, smaller number is more prioriable.

$ python sched_priority.py

START: 1361446608.62
EVENT: 1361446610.62 second
EVENT: 1361446610.62 first

 

相关文章:

  • 2022-12-23
  • 2021-06-04
  • 2021-04-08
  • 2021-09-11
  • 2022-01-27
  • 2021-12-06
  • 2021-08-15
  • 2022-12-23
猜你喜欢
  • 2021-12-01
  • 2021-09-03
  • 2022-12-23
  • 2021-10-04
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
相关资源
相似解决方案