annotate Lib/Queue.py @ 24042:63fbbed10714 legacy-trunk

Simplify HTTPSConnection constructor. See discussion in SF bug 458463.
author Jeremy Hylton <jeremy@alum.mit.edu>
date Fri, 28 Jun 2002 23:38:14 +0000
parents c548e726b3bc
children aef248c1645a 37ffce2d9c3c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11691
e34991022571 Mass patch by Ka-Ping Yee:
Guido van Rossum <guido@python.org>
parents: 11267
diff changeset
1 """A multi-producer, multi-consumer queue."""
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
15902
eef321b6e41c Variant of Skip's patch 103246 (Remove unneeded string exception compat from Queue).
Tim Peters <tim.peters@gmail.com>
parents: 13050
diff changeset
3 class Empty(Exception):
eef321b6e41c Variant of Skip's patch 103246 (Remove unneeded string exception compat from Queue).
Tim Peters <tim.peters@gmail.com>
parents: 13050
diff changeset
4 "Exception raised by Queue.get(block=0)/get_nowait()."
eef321b6e41c Variant of Skip's patch 103246 (Remove unneeded string exception compat from Queue).
Tim Peters <tim.peters@gmail.com>
parents: 13050
diff changeset
5 pass
eef321b6e41c Variant of Skip's patch 103246 (Remove unneeded string exception compat from Queue).
Tim Peters <tim.peters@gmail.com>
parents: 13050
diff changeset
6
eef321b6e41c Variant of Skip's patch 103246 (Remove unneeded string exception compat from Queue).
Tim Peters <tim.peters@gmail.com>
parents: 13050
diff changeset
7 class Full(Exception):
eef321b6e41c Variant of Skip's patch 103246 (Remove unneeded string exception compat from Queue).
Tim Peters <tim.peters@gmail.com>
parents: 13050
diff changeset
8 "Exception raised by Queue.put(block=0)/put_nowait()."
eef321b6e41c Variant of Skip's patch 103246 (Remove unneeded string exception compat from Queue).
Tim Peters <tim.peters@gmail.com>
parents: 13050
diff changeset
9 pass
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 class Queue:
11267
2b26e48a85a6 Make the maxsize constructor argument default to 0 (an unlimited queue size).
Guido van Rossum <guido@python.org>
parents: 10120
diff changeset
12 def __init__(self, maxsize=0):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
13 """Initialize a queue object with a given maximum size.
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
15 If maxsize is <= 0, the queue size is infinite.
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
16 """
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
17 import thread
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
18 self._init(maxsize)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
19 self.mutex = thread.allocate_lock()
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
20 self.esema = thread.allocate_lock()
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
21 self.esema.acquire()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
22 self.fsema = thread.allocate_lock()
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
24 def qsize(self):
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
25 """Return the approximate size of the queue (not reliable!)."""
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
26 self.mutex.acquire()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
27 n = self._qsize()
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
28 self.mutex.release()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
29 return n
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
30
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
31 def empty(self):
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
32 """Return 1 if the queue is empty, 0 otherwise (not reliable!)."""
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
33 self.mutex.acquire()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
34 n = self._empty()
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
35 self.mutex.release()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
36 return n
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
38 def full(self):
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
39 """Return 1 if the queue is full, 0 otherwise (not reliable!)."""
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
40 self.mutex.acquire()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
41 n = self._full()
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
42 self.mutex.release()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
43 return n
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
44
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
45 def put(self, item, block=1):
7926
e29d435ab142 Clarify that put *blocks* when the queue is full. Add some blank
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
46 """Put an item into the queue.
e29d435ab142 Clarify that put *blocks* when the queue is full. Add some blank
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
47
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
48 If optional arg 'block' is 1 (the default), block if
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
49 necessary until a free slot is available. Otherwise (block
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
50 is 0), put an item on the queue if a free slot is immediately
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
51 available, else raise the Full exception.
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
52 """
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
53 if block:
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
54 self.fsema.acquire()
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
55 elif not self.fsema.acquire(0):
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
56 raise Full
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
57 self.mutex.acquire()
23160
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
58 release_fsema = True
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
59 try:
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
60 was_empty = self._empty()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
61 self._put(item)
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
62 # If we fail before here, the empty state has
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
63 # not changed, so we can skip the release of esema
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
64 if was_empty:
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
65 self.esema.release()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
66 # If we fail before here, the queue can not be full, so
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
67 # release_full_sema remains True
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
68 release_fsema = not self._full()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
69 finally:
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
70 # Catching system level exceptions here (RecursionDepth,
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
71 # OutOfMemory, etc) - so do as little as possible in terms
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
72 # of Python calls.
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
73 if release_fsema:
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
74 self.fsema.release()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
75 self.mutex.release()
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
77 def put_nowait(self, item):
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
78 """Put an item into the queue without blocking.
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
79
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
80 Only enqueue the item if a free slot is immediately available.
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
81 Otherwise raise the Full exception.
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
82 """
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
83 return self.put(item, 0)
7926
e29d435ab142 Clarify that put *blocks* when the queue is full. Add some blank
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
84
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
85 def get(self, block=1):
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
86 """Remove and return an item from the queue.
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
87
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
88 If optional arg 'block' is 1 (the default), block if
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
89 necessary until an item is available. Otherwise (block is 0),
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
90 return an item if one is immediately available, else raise the
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
91 Empty exception.
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
92 """
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
93 if block:
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
94 self.esema.acquire()
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
95 elif not self.esema.acquire(0):
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
96 raise Empty
8197
3a55b4c5e3c7 Replace all calls to acquire_lock() and release_lock() with acquire()
Guido van Rossum <guido@python.org>
parents: 7926
diff changeset
97 self.mutex.acquire()
23160
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
98 release_esema = True
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
99 try:
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
100 was_full = self._full()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
101 item = self._get()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
102 # If we fail before here, the full state has
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
103 # not changed, so we can skip the release of fsema
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
104 if was_full:
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
105 self.fsema.release()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
106 # Failure means empty state also unchanged - release_esema
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
107 # remains True.
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
108 release_esema = not self._empty()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
109 finally:
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
110 if release_esema:
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
111 self.esema.release()
c548e726b3bc Fix bug 544473 - "Queue module can deadlock".
Mark Hammond <mhammond@skippinet.com.au>
parents: 16657
diff changeset
112 self.mutex.release()
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
113 return item
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
114
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
115 def get_nowait(self):
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
116 """Remove and return an item from the queue without blocking.
7926
e29d435ab142 Clarify that put *blocks* when the queue is full. Add some blank
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
117
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
118 Only get an item if one is immediately available. Otherwise
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
119 raise the Empty exception.
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
120 """
10120
5b15642e7bdf Tim Peters:
Guido van Rossum <guido@python.org>
parents: 8197
diff changeset
121 return self.get(0)
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
122
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
123 # Override these methods to implement other queue organizations
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
124 # (e.g. stack or priority queue).
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
125 # These will only be called with appropriate locks held
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
126
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
127 # Initialize the queue representation
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
128 def _init(self, maxsize):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
129 self.maxsize = maxsize
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
130 self.queue = []
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
131
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
132 def _qsize(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
133 return len(self.queue)
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
13050
a195962e389c typos fixed by Rob Hooft
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 11691
diff changeset
135 # Check whether the queue is empty
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
136 def _empty(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
137 return not self.queue
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
138
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
139 # Check whether the queue is full
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
140 def _full(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
141 return self.maxsize > 0 and len(self.queue) == self.maxsize
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
142
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
143 # Put a new item in the queue
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
144 def _put(self, item):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
145 self.queue.append(item)
995
f025eef93130 New module implementing a multi-everything queue.
Guido van Rossum <guido@python.org>
parents:
diff changeset
146
6612
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
147 # Get an item from the queue
4b2d8dc92db4 (Queue.Empty): When class based exceptions are in force, derive this
Barry Warsaw <barry@python.org>
parents: 1463
diff changeset
148 def _get(self):
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
149 item = self.queue[0]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
150 del self.queue[0]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 6612
diff changeset
151 return item