Skip to content

Commit f260e44

Browse files
committed
Rename Queue module to queue.
Updated documentation to use new name. Merged revisions 63077 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r63077 | alexandre.vassalotti | 2008-05-11 15:39:48 -0400 (Sun, 11 May 2008) | 3 lines Added stub for the Queue module to be renamed in 3.0. Use the 3.0 module name to avoid spurious warnings. ........
1 parent 4e3e21e commit f260e44

File tree

12 files changed

+49
-33
lines changed

12 files changed

+49
-33
lines changed

Doc/library/queue.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
:mod:`Queue` --- A synchronized queue class
2+
:mod:`queue` --- A synchronized queue class
33
===========================================
44

5-
.. module:: Queue
5+
.. module:: queue
66
:synopsis: A synchronized queue class.
77

88

9-
The :mod:`Queue` module implements multi-producer, multi-consumer queues.
9+
The :mod:`queue` module implements multi-producer, multi-consumer queues.
1010
It is especially useful in threaded programming when information must be
1111
exchanged safely between multiple threads. The :class:`Queue` class in this
1212
module implements all the required locking semantics. It depends on the
@@ -20,7 +20,7 @@ the first retrieved (operating like a stack). With a priority queue,
2020
the entries are kept sorted (using the :mod:`heapq` module) and the
2121
lowest valued entry is retrieved first.
2222

23-
The :mod:`Queue` module defines the following classes and exceptions:
23+
The :mod:`queue` module defines the following classes and exceptions:
2424

2525
.. class:: Queue(maxsize)
2626

Doc/library/threading.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
This module constructs higher-level threading interfaces on top of the lower
1010
level :mod:`thread` module.
11-
See also the :mod:`Queue` module.
11+
See also the :mod:`queue` module.
1212

1313
The :mod:`dummy_threading` module is provided for situations where
1414
:mod:`threading` cannot be used because :mod:`thread` is missing.

Doc/reference/simple_stmts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ The :keyword:`raise` statement
485485
If no expressions are present, :keyword:`raise` re-raises the last exception
486486
that was active in the current scope. If no exception is active in the current
487487
scope, a :exc:`TypeError` exception is raised indicating that this is an error
488-
(if running under IDLE, a :exc:`Queue.Empty` exception is raised instead).
488+
(if running under IDLE, a :exc:`queue.Empty` exception is raised instead).
489489

490490
Otherwise, :keyword:`raise` evaluates the first expression as the exception
491491
object. It must be either a subclass or an instance of :class:`BaseException`.

Doc/tutorial/stdlib2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ variables, and semaphores.
198198
While those tools are powerful, minor design errors can result in problems that
199199
are difficult to reproduce. So, the preferred approach to task coordination is
200200
to concentrate all access to a resource in a single thread and then use the
201-
:mod:`Queue` module to feed that thread with requests from other threads.
201+
:mod:`queue` module to feed that thread with requests from other threads.
202202
Applications using :class:`Queue` objects for inter-thread communication and
203203
coordination are easier to design, more readable, and more reliable.
204204

Lib/idlelib/rpc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import struct
3636
import pickle
3737
import threading
38-
import Queue
38+
import queue
3939
import traceback
4040
import copyreg
4141
import types
@@ -117,8 +117,8 @@ def handle_error(self, request, client_address):
117117
#----------------- end class RPCServer --------------------
118118

119119
objecttable = {}
120-
request_queue = Queue.Queue(0)
121-
response_queue = Queue.Queue(0)
120+
request_queue = queue.Queue(0)
121+
response_queue = queue.Queue(0)
122122

123123

124124
class SocketIO(object):
@@ -413,7 +413,7 @@ def pollresponse(self, myseq, wait):
413413
# send queued response if there is one available
414414
try:
415415
qmsg = response_queue.get(0)
416-
except Queue.Empty:
416+
except queue.Empty:
417417
pass
418418
else:
419419
seq, response = qmsg

Lib/idlelib/run.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import traceback
66
import thread
77
import threading
8-
import Queue
8+
import queue
99

1010
from idlelib import CallTips
1111
from idlelib import AutoComplete
@@ -85,7 +85,7 @@ def main(del_exitfunc=False):
8585
continue
8686
try:
8787
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
88-
except Queue.Empty:
88+
except queue.Empty:
8989
continue
9090
method, args, kwargs = request
9191
ret = method(*args, **kwargs)

Lib/Queue.py renamed to Lib/queue.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ def qsize(self):
9090
self.mutex.release()
9191
return n
9292

93+
def empty(self):
94+
"""Return True if the queue is empty, False otherwise (not reliable!)."""
95+
self.mutex.acquire()
96+
n = not self._qsize()
97+
self.mutex.release()
98+
return n
99+
100+
def full(self):
101+
"""Return True if the queue is full, False otherwise (not reliable!)."""
102+
self.mutex.acquire()
103+
n = 0 < self.maxsize == self._qsize()
104+
self.mutex.release()
105+
return n
106+
93107
def put(self, item, block=True, timeout=None):
94108
"""Put an item into the queue.
95109

Lib/test/test_dummy_thread.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88
import dummy_thread as _thread
99
import time
10-
import Queue
10+
import queue
1111
import random
1212
import unittest
1313
from test import test_support
@@ -124,7 +124,7 @@ def arg_tester(queue, arg1=False, arg2=False):
124124
"""Use to test _thread.start_new_thread() passes args properly."""
125125
queue.put((arg1, arg2))
126126

127-
testing_queue = Queue.Queue(1)
127+
testing_queue = queue.Queue(1)
128128
_thread.start_new_thread(arg_tester, (testing_queue, True, True))
129129
result = testing_queue.get()
130130
self.failUnless(result[0] and result[1],
@@ -148,7 +148,7 @@ def queue_mark(queue, delay):
148148
queue.put(_thread.get_ident())
149149

150150
thread_count = 5
151-
testing_queue = Queue.Queue(thread_count)
151+
testing_queue = queue.Queue(thread_count)
152152
if test_support.verbose:
153153
print()
154154
print("*** Testing multiple thread creation "\

Lib/test/test_queue.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Some simple Queue module tests, plus some failure conditions
1+
# Some simple queue module tests, plus some failure conditions
22
# to ensure the Queue locks remain stable.
3-
import Queue
3+
import queue
44
import sys
55
import threading
66
import time
@@ -112,12 +112,12 @@ def simple_queue_test(self, q):
112112
try:
113113
q.put(full, block=0)
114114
self.fail("Didn't appear to block with a full queue")
115-
except Queue.Full:
115+
except queue.Full:
116116
pass
117117
try:
118118
q.put(full, timeout=0.01)
119119
self.fail("Didn't appear to time-out with a full queue")
120-
except Queue.Full:
120+
except queue.Full:
121121
pass
122122
# Test a blocking put
123123
self.do_blocking_test(q.put, (full,), q.get, ())
@@ -129,12 +129,12 @@ def simple_queue_test(self, q):
129129
try:
130130
q.get(block=0)
131131
self.fail("Didn't appear to block with an empty queue")
132-
except Queue.Empty:
132+
except queue.Empty:
133133
pass
134134
try:
135135
q.get(timeout=0.01)
136136
self.fail("Didn't appear to time-out with an empty queue")
137-
except Queue.Empty:
137+
except queue.Empty:
138138
pass
139139
# Test a blocking get
140140
self.do_blocking_test(q.get, (), q.put, ('empty',))
@@ -196,35 +196,35 @@ def test_simple_queue(self):
196196

197197

198198
class QueueTest(BaseQueueTest):
199-
type2test = Queue.Queue
199+
type2test = queue.Queue
200200

201201
class LifoQueueTest(BaseQueueTest):
202-
type2test = Queue.LifoQueue
202+
type2test = queue.LifoQueue
203203

204204
class PriorityQueueTest(BaseQueueTest):
205-
type2test = Queue.PriorityQueue
205+
type2test = queue.PriorityQueue
206206

207207

208208

209209
# A Queue subclass that can provoke failure at a moment's notice :)
210210
class FailingQueueException(Exception):
211211
pass
212212

213-
class FailingQueue(Queue.Queue):
213+
class FailingQueue(queue.Queue):
214214
def __init__(self, *args):
215215
self.fail_next_put = False
216216
self.fail_next_get = False
217-
Queue.Queue.__init__(self, *args)
217+
queue.Queue.__init__(self, *args)
218218
def _put(self, item):
219219
if self.fail_next_put:
220220
self.fail_next_put = False
221221
raise FailingQueueException("You Lose")
222-
return Queue.Queue._put(self, item)
222+
return queue.Queue._put(self, item)
223223
def _get(self):
224224
if self.fail_next_get:
225225
self.fail_next_get = False
226226
raise FailingQueueException("You Lose")
227-
return Queue.Queue._get(self)
227+
return queue.Queue._get(self)
228228

229229
class FailingQueueTest(unittest.TestCase, BlockingTestMixin):
230230

Lib/test/test_socket.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import thread, threading
1010
import time
1111
import traceback
12-
import Queue
12+
import queue
1313
import sys
1414
import os
1515
import array
@@ -96,7 +96,7 @@ def _setUp(self):
9696
self.server_ready = threading.Event()
9797
self.client_ready = threading.Event()
9898
self.done = threading.Event()
99-
self.queue = Queue.Queue(1)
99+
self.queue = queue.Queue(1)
100100

101101
# Do some munging to start the client test.
102102
methodname = self.id()

0 commit comments

Comments
 (0)