1
# -*- test-case-name: twisted.test.test_timeoutqueue -*-
2
# Copyright (c) 2001-2007 Twisted Matrix Laboratories.
3
# See LICENSE for details.
6
A Queue subclass that supports timeouts.
10
import Queue, time, warnings
17
class TimedOut(Exception):
21
class TimeoutQueue(Queue.Queue):
23
A thread-safe queue that supports timeouts.
26
def __init__(self, max=0):
27
warnings.warn("timeoutqueue is deprecated since Twisted 8.0",
28
category=DeprecationWarning, stacklevel=2)
29
Queue.Queue.__init__(self, max)
31
def wait(self, timeout):
33
Wait until the queue isn't empty. Raises TimedOut if still empty.
35
endtime = _time() + timeout
36
delay = 0.0005 # 500 us -> initial delay of 1 ms
38
gotit = not self.empty()
41
remaining = endtime - _time()
43
raise TimedOut, "timed out."
44
delay = min(delay * 2, remaining, .05)
48
__all__ = ["TimeoutQueue", "TimedOut"]