mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-24 11:39:25 +01:00
Fixes for TimeoutQueue.
This commit is contained in:
parent
142349847b
commit
cf52bf14a3
@ -311,11 +311,20 @@ class TimeoutQueue(object):
|
|||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
|
||||||
|
def _getTimeout(self):
|
||||||
|
if callable(self.timeout):
|
||||||
|
return self.timeout()
|
||||||
|
else:
|
||||||
|
return self.timeout
|
||||||
|
|
||||||
def _clearOldElements(self):
|
def _clearOldElements(self):
|
||||||
now = time.time()
|
now = time.time()
|
||||||
while now - self.queue.peek()[0] > self.timeout:
|
while now - self.queue.peek()[0] > self._getTimeout():
|
||||||
self.queue.dequeue()
|
self.queue.dequeue()
|
||||||
|
|
||||||
|
def setTimeout(self, i):
|
||||||
|
self.timeout = i
|
||||||
|
|
||||||
def enqueue(self, elt, at=None):
|
def enqueue(self, elt, at=None):
|
||||||
if at is None:
|
if at is None:
|
||||||
at = time.time()
|
at = time.time()
|
||||||
@ -330,7 +339,7 @@ class TimeoutQueue(object):
|
|||||||
# the resulting generator and elements that should've timed out are
|
# the resulting generator and elements that should've timed out are
|
||||||
# yielded? Hmm? What happens then, smarty-pants?
|
# yielded? Hmm? What happens then, smarty-pants?
|
||||||
for (t, elt) in self.queue:
|
for (t, elt) in self.queue:
|
||||||
if time.time() - t < self.timeout:
|
if time.time() - t < self._getTimeout():
|
||||||
yield elt
|
yield elt
|
||||||
|
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user