| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4e3e21e commit f260e44
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,12 +1,12 @@ | |||
| 1 | 1 | ||
| 2 | - :mod:`Queue` --- A synchronized queue class | ||
| 2 | + :mod:`queue` --- A synchronized queue class | ||
| 3 | 3 | =========================================== | |
| 4 | 4 | ||
| 5 | - .. module:: Queue | ||
| 5 | + .. module:: queue | ||
| 6 | 6 | :synopsis: A synchronized queue class. | |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | - The :mod:`Queue` module implements multi-producer, multi-consumer queues. | ||
| 9 | + The :mod:`queue` module implements multi-producer, multi-consumer queues. | ||
| 10 | 10 | It is especially useful in threaded programming when information must be | |
| 11 | 11 | exchanged safely between multiple threads. The :class:`Queue` class in this | |
| 12 | 12 | 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, | |||
| 20 | 20 | the entries are kept sorted (using the :mod:`heapq` module) and the | |
| 21 | 21 | lowest valued entry is retrieved first. | |
| 22 | 22 | ||
| 23 | - The :mod:`Queue` module defines the following classes and exceptions: | ||
| 23 | + The :mod:`queue` module defines the following classes and exceptions: | ||
| 24 | 24 | ||
| 25 | 25 | .. class:: Queue(maxsize) | |
| 26 | 26 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | 9 | This module constructs higher-level threading interfaces on top of the lower | |
| 10 | 10 | level :mod:`thread` module. | |
| 11 | - See also the :mod:`Queue` module. | ||
| 11 | + See also the :mod:`queue` module. | ||
| 12 | 12 | ||
| 13 | 13 | The :mod:`dummy_threading` module is provided for situations where | |
| 14 | 14 | :mod:`threading` cannot be used because :mod:`thread` is missing. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -485,7 +485,7 @@ The :keyword:`raise` statement | |||
| 485 | 485 | If no expressions are present, :keyword:`raise` re-raises the last exception | |
| 486 | 486 | that was active in the current scope. If no exception is active in the current | |
| 487 | 487 | 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). | ||
| 489 | 489 | ||
| 490 | 490 | Otherwise, :keyword:`raise` evaluates the first expression as the exception | |
| 491 | 491 | object. It must be either a subclass or an instance of :class:`BaseException`. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -198,7 +198,7 @@ variables, and semaphores. | |||
| 198 | 198 | While those tools are powerful, minor design errors can result in problems that | |
| 199 | 199 | are difficult to reproduce. So, the preferred approach to task coordination is | |
| 200 | 200 | 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. | ||
| 202 | 202 | Applications using :class:`Queue` objects for inter-thread communication and | |
| 203 | 203 | coordination are easier to design, more readable, and more reliable. | |
| 204 | 204 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,7 +35,7 @@ | |||
| 35 | 35 | import struct | |
| 36 | 36 | import pickle | |
| 37 | 37 | import threading | |
| 38 | - import Queue | ||
| 38 | + import queue | ||
| 39 | 39 | import traceback | |
| 40 | 40 | import copyreg | |
| 41 | 41 | import types | |
@@ -117,8 +117,8 @@ def handle_error(self, request, client_address): | |||
| 117 | 117 | #----------------- end class RPCServer -------------------- | |
| 118 | 118 | ||
| 119 | 119 | 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) | ||
| 122 | 122 | ||
| 123 | 123 | ||
| 124 | 124 | class SocketIO(object): | |
@@ -413,7 +413,7 @@ def pollresponse(self, myseq, wait): | |||
| 413 | 413 | # send queued response if there is one available | |
| 414 | 414 | try: | |
| 415 | 415 | qmsg = response_queue.get(0) | |
| 416 | - except Queue.Empty: | ||
| 416 | + except queue.Empty: | ||
| 417 | 417 | pass | |
| 418 | 418 | else: | |
| 419 | 419 | seq, response = qmsg | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | import traceback | |
| 6 | 6 | import thread | |
| 7 | 7 | import threading | |
| 8 | - import Queue | ||
| 8 | + import queue | ||
| 9 | 9 | ||
| 10 | 10 | from idlelib import CallTips | |
| 11 | 11 | from idlelib import AutoComplete | |
@@ -85,7 +85,7 @@ def main(del_exitfunc=False): | |||
| 85 | 85 | continue | |
| 86 | 86 | try: | |
| 87 | 87 | seq, request = rpc.request_queue.get(block=True, timeout=0.05) | |
| 88 | - except Queue.Empty: | ||
| 88 | + except queue.Empty: | ||
| 89 | 89 | continue | |
| 90 | 90 | method, args, kwargs = request | |
| 91 | 91 | ret = method(*args, **kwargs) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -90,6 +90,20 @@ def qsize(self): | |||
| 90 | 90 | self.mutex.release() | |
| 91 | 91 | return n | |
| 92 | 92 | ||
| 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 | + | ||
| 93 | 107 | def put(self, item, block=True, timeout=None): | |
| 94 | 108 | """Put an item into the queue. | |
| 95 | 109 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | """ | |
| 8 | 8 | import dummy_thread as _thread | |
| 9 | 9 | import time | |
| 10 | - import Queue | ||
| 10 | + import queue | ||
| 11 | 11 | import random | |
| 12 | 12 | import unittest | |
| 13 | 13 | from test import test_support | |
@@ -124,7 +124,7 @@ def arg_tester(queue, arg1=False, arg2=False): | |||
| 124 | 124 | """Use to test _thread.start_new_thread() passes args properly.""" | |
| 125 | 125 | queue.put((arg1, arg2)) | |
| 126 | 126 | ||
| 127 | - testing_queue = Queue.Queue(1) | ||
| 127 | + testing_queue = queue.Queue(1) | ||
| 128 | 128 | _thread.start_new_thread(arg_tester, (testing_queue, True, True)) | |
| 129 | 129 | result = testing_queue.get() | |
| 130 | 130 | self.failUnless(result[0] and result[1], | |
@@ -148,7 +148,7 @@ def queue_mark(queue, delay): | |||
| 148 | 148 | queue.put(_thread.get_ident()) | |
| 149 | 149 | ||
| 150 | 150 | thread_count = 5 | |
| 151 | - testing_queue = Queue.Queue(thread_count) | ||
| 151 | + testing_queue = queue.Queue(thread_count) | ||
| 152 | 152 | if test_support.verbose: | |
| 153 | 153 | print() | |
| 154 | 154 | print("*** Testing multiple thread creation "\ | |
| Original file line number | Diff line number | Diff 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 | ||
| 2 | 2 | # to ensure the Queue locks remain stable. | |
| 3 | - import Queue | ||
| 3 | + import queue | ||
| 4 | 4 | import sys | |
| 5 | 5 | import threading | |
| 6 | 6 | import time | |
@@ -112,12 +112,12 @@ def simple_queue_test(self, q): | |||
| 112 | 112 | try: | |
| 113 | 113 | q.put(full, block=0) | |
| 114 | 114 | self.fail("Didn't appear to block with a full queue") | |
| 115 | - except Queue.Full: | ||
| 115 | + except queue.Full: | ||
| 116 | 116 | pass | |
| 117 | 117 | try: | |
| 118 | 118 | q.put(full, timeout=0.01) | |
| 119 | 119 | self.fail("Didn't appear to time-out with a full queue") | |
| 120 | - except Queue.Full: | ||
| 120 | + except queue.Full: | ||
| 121 | 121 | pass | |
| 122 | 122 | # Test a blocking put | |
| 123 | 123 | self.do_blocking_test(q.put, (full,), q.get, ()) | |
@@ -129,12 +129,12 @@ def simple_queue_test(self, q): | |||
| 129 | 129 | try: | |
| 130 | 130 | q.get(block=0) | |
| 131 | 131 | self.fail("Didn't appear to block with an empty queue") | |
| 132 | - except Queue.Empty: | ||
| 132 | + except queue.Empty: | ||
| 133 | 133 | pass | |
| 134 | 134 | try: | |
| 135 | 135 | q.get(timeout=0.01) | |
| 136 | 136 | self.fail("Didn't appear to time-out with an empty queue") | |
| 137 | - except Queue.Empty: | ||
| 137 | + except queue.Empty: | ||
| 138 | 138 | pass | |
| 139 | 139 | # Test a blocking get | |
| 140 | 140 | self.do_blocking_test(q.get, (), q.put, ('empty',)) | |
@@ -196,35 +196,35 @@ def test_simple_queue(self): | |||
| 196 | 196 | ||
| 197 | 197 | ||
| 198 | 198 | class QueueTest(BaseQueueTest): | |
| 199 | - type2test = Queue.Queue | ||
| 199 | + type2test = queue.Queue | ||
| 200 | 200 | ||
| 201 | 201 | class LifoQueueTest(BaseQueueTest): | |
| 202 | - type2test = Queue.LifoQueue | ||
| 202 | + type2test = queue.LifoQueue | ||
| 203 | 203 | ||
| 204 | 204 | class PriorityQueueTest(BaseQueueTest): | |
| 205 | - type2test = Queue.PriorityQueue | ||
| 205 | + type2test = queue.PriorityQueue | ||
| 206 | 206 | ||
| 207 | 207 | ||
| 208 | 208 | ||
| 209 | 209 | # A Queue subclass that can provoke failure at a moment's notice :) | |
| 210 | 210 | class FailingQueueException(Exception): | |
| 211 | 211 | pass | |
| 212 | 212 | ||
| 213 | - class FailingQueue(Queue.Queue): | ||
| 213 | + class FailingQueue(queue.Queue): | ||
| 214 | 214 | def __init__(self, *args): | |
| 215 | 215 | self.fail_next_put = False | |
| 216 | 216 | self.fail_next_get = False | |
| 217 | - Queue.Queue.__init__(self, *args) | ||
| 217 | + queue.Queue.__init__(self, *args) | ||
| 218 | 218 | def _put(self, item): | |
| 219 | 219 | if self.fail_next_put: | |
| 220 | 220 | self.fail_next_put = False | |
| 221 | 221 | raise FailingQueueException("You Lose") | |
| 222 | - return Queue.Queue._put(self, item) | ||
| 222 | + return queue.Queue._put(self, item) | ||
| 223 | 223 | def _get(self): | |
| 224 | 224 | if self.fail_next_get: | |
| 225 | 225 | self.fail_next_get = False | |
| 226 | 226 | raise FailingQueueException("You Lose") | |
| 227 | - return Queue.Queue._get(self) | ||
| 227 | + return queue.Queue._get(self) | ||
| 228 | 228 | ||
| 229 | 229 | class FailingQueueTest(unittest.TestCase, BlockingTestMixin): | |
| 230 | 230 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ | |||
| 9 | 9 | import thread, threading | |
| 10 | 10 | import time | |
| 11 | 11 | import traceback | |
| 12 | - import Queue | ||
| 12 | + import queue | ||
| 13 | 13 | import sys | |
| 14 | 14 | import os | |
| 15 | 15 | import array | |
@@ -96,7 +96,7 @@ def _setUp(self): | |||
| 96 | 96 | self.server_ready = threading.Event() | |
| 97 | 97 | self.client_ready = threading.Event() | |
| 98 | 98 | self.done = threading.Event() | |
| 99 | - self.queue = Queue.Queue(1) | ||
| 99 | + self.queue = queue.Queue(1) | ||
| 100 | 100 | ||
| 101 | 101 | # Do some munging to start the client test. | |
| 102 | 102 | methodname = self.id() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments