micro-optimize no timer case
This commit is contained in:
@@ -973,20 +973,22 @@ class TimerManager(object):
|
||||
:return: next end time, or None
|
||||
"""
|
||||
queue = self._queue
|
||||
new_timers = self._new_timers
|
||||
while new_timers:
|
||||
heappush(queue, new_timers.pop())
|
||||
if self._new_timers:
|
||||
new_timers = self._new_timers
|
||||
while new_timers:
|
||||
heappush(queue, new_timers.pop())
|
||||
|
||||
now = time.time()
|
||||
while queue:
|
||||
try:
|
||||
timer = queue[0][1]
|
||||
if timer.finish(now):
|
||||
heappop(queue)
|
||||
else:
|
||||
return timer.end
|
||||
except Exception:
|
||||
log.exception("Exception while servicing timeout callback: ")
|
||||
if queue:
|
||||
now = time.time()
|
||||
while queue:
|
||||
try:
|
||||
timer = queue[0][1]
|
||||
if timer.finish(now):
|
||||
heappop(queue)
|
||||
else:
|
||||
return timer.end
|
||||
except Exception:
|
||||
log.exception("Exception while servicing timeout callback: ")
|
||||
|
||||
@property
|
||||
def next_timeout(self):
|
||||
@@ -994,11 +996,3 @@ class TimerManager(object):
|
||||
return self._queue[0][0]
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
@property
|
||||
def next_offset(self):
|
||||
try:
|
||||
next_end = self._queue[0][0]
|
||||
return next_end - time.time()
|
||||
except IndexError:
|
||||
pass
|
||||
|
@@ -19,6 +19,7 @@ import os
|
||||
import socket
|
||||
import ssl
|
||||
from threading import Lock, Thread
|
||||
import time
|
||||
import weakref
|
||||
|
||||
from six.moves import range
|
||||
@@ -144,9 +145,9 @@ class LibevLoop(object):
|
||||
|
||||
def _update_timer(self):
|
||||
if not self._shutdown:
|
||||
self._timers.service_timeouts()
|
||||
offset = self._timers.next_offset or 100000 # none pending; will be updated again when something new happens
|
||||
self._loop_timer.start(offset)
|
||||
next_end = self._timers.service_timeouts()
|
||||
if next_end:
|
||||
self._loop_timer.start(next_end - time.time()) # timer handles negative values
|
||||
else:
|
||||
self._loop_timer.stop()
|
||||
|
||||
|
Reference in New Issue
Block a user