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