def seconds_until_wakeup(cls):
"""
Calculate delay until next timer expires, or None if no timers are
set and we should wait indefinitely. Rounds up to avoid spinning
in select() or poll(). We could calculate fractional seconds in
the right units instead, but select() and poll() don't even take
the same units (argh!), and we're not doing anything that
hair-triggered, so rounding up is simplest.
"""
if not timer_queue:
return None
now = rpki.sundial.now()
if now >= timer_queue[0].when:
return 0
delay = timer_queue[0].when - now
seconds = delay.convert_to_seconds()
if delay.microseconds:
seconds += 1
return seconds
评论列表
文章目录