Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/twisted_8_1/twisted/python/timeoutqueue.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # -*- test-case-name: twisted.test.test_timeoutqueue -*-
2 # Copyright (c) 2001-2007 Twisted Matrix Laboratories.
3 # See LICENSE for details.
4
5 """
6 A Queue subclass that supports timeouts.
7 """
8
9 # System Imports
10 import Queue, time, warnings
11
12
13 _time = time.time
14 _sleep = time.sleep
15
16
17 class TimedOut(Exception):
18 pass
19
20
21 class TimeoutQueue(Queue.Queue):
22 """
23 A thread-safe queue that supports timeouts.
24 """
25
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)
30
31 def wait(self, timeout):
32 """
33 Wait until the queue isn't empty. Raises TimedOut if still empty.
34 """
35 endtime = _time() + timeout
36 delay = 0.0005 # 500 us -> initial delay of 1 ms
37 while 1:
38 gotit = not self.empty()
39 if gotit:
40 break
41 remaining = endtime - _time()
42 if remaining <= 0:
43 raise TimedOut, "timed out."
44 delay = min(delay * 2, remaining, .05)
45 _sleep(delay)
46
47
48 __all__ = ["TimeoutQueue", "TimedOut"]
49
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/python/threadpool.py ('k') | third_party/twisted_8_1/twisted/python/urlpath.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698