1- """ A multi-producer, multi-consumer queue."""
1+ ''' A multi-producer, multi-consumer queue.'''
22
33try :
44 import threading
1111__all__ = ['Empty' , 'Full' , 'Queue' , 'PriorityQueue' , 'LifoQueue' ]
1212
1313class Empty (Exception ):
14- " Exception raised by Queue.get(block=0)/get_nowait()."
14+ ' Exception raised by Queue.get(block=0)/get_nowait().'
1515 pass
1616
1717class Full (Exception ):
18- " Exception raised by Queue.put(block=0)/put_nowait()."
18+ ' Exception raised by Queue.put(block=0)/put_nowait().'
1919 pass
2020
2121class Queue :
22- """ Create a queue object with a given maximum size.
22+ ''' Create a queue object with a given maximum size.
2323
2424 If maxsize is <= 0, the queue size is infinite.
25- """
25+ '''
26+
2627 def __init__ (self , maxsize = 0 ):
2728 self .maxsize = maxsize
2829 self ._init (maxsize )
@@ -47,7 +48,7 @@ def __init__(self, maxsize=0):
4748 self .unfinished_tasks = 0
4849
4950 def task_done (self ):
50- """ Indicate that a formerly enqueued task is complete.
51+ ''' Indicate that a formerly enqueued task is complete.
5152
5253 Used by Queue consumer threads. For each get() used to fetch a task,
5354 a subsequent call to task_done() tells the queue that the processing
@@ -59,7 +60,7 @@ def task_done(self):
5960
6061 Raises a ValueError if called more times than there were items
6162 placed in the queue.
62- """
63+ '''
6364 with self .all_tasks_done :
6465 unfinished = self .unfinished_tasks - 1
6566 if unfinished <= 0 :
@@ -69,25 +70,25 @@ def task_done(self):
6970 self .unfinished_tasks = unfinished
7071
7172 def join (self ):
72- """ Blocks until all items in the Queue have been gotten and processed.
73+ ''' Blocks until all items in the Queue have been gotten and processed.
7374
7475 The count of unfinished tasks goes up whenever an item is added to the
7576 queue. The count goes down whenever a consumer thread calls task_done()
7677 to indicate the item was retrieved and all work on it is complete.
7778
7879 When the count of unfinished tasks drops to zero, join() unblocks.
79- """
80+ '''
8081 with self .all_tasks_done :
8182 while self .unfinished_tasks :
8283 self .all_tasks_done .wait ()
8384
8485 def qsize (self ):
85- """ Return the approximate size of the queue (not reliable!)."""
86+ ''' Return the approximate size of the queue (not reliable!).'''
8687 with self .mutex :
8788 return self ._qsize ()
8889
8990 def empty (self ):
90- """ Return True if the queue is empty, False otherwise (not reliable!).
91+ ''' Return True if the queue is empty, False otherwise (not reliable!).
9192
9293 This method is likely to be removed at some point. Use qsize() == 0
9394 as a direct substitute, but be aware that either approach risks a race
@@ -96,25 +97,23 @@ def empty(self):
9697
9798 To create code that needs to wait for all queued tasks to be
9899 completed, the preferred technique is to use the join() method.
99-
100- """
100+ '''
101101 with self .mutex :
102102 return not self ._qsize ()
103103
104104 def full (self ):
105- """ Return True if the queue is full, False otherwise (not reliable!).
105+ ''' Return True if the queue is full, False otherwise (not reliable!).
106106
107107 This method is likely to be removed at some point. Use qsize() >= n
108108 as a direct substitute, but be aware that either approach risks a race
109109 condition where a queue can shrink before the result of full() or
110110 qsize() can be used.
111-
112- """
111+ '''
113112 with self .mutex :
114113 return 0 < self .maxsize <= self ._qsize ()
115114
116115 def put (self , item , block = True , timeout = None ):
117- """ Put an item into the queue.
116+ ''' Put an item into the queue.
118117
119118 If optional args 'block' is true and 'timeout' is None (the default),
120119 block if necessary until a free slot is available. If 'timeout' is
@@ -123,7 +122,7 @@ def put(self, item, block=True, timeout=None):
123122 Otherwise ('block' is false), put an item on the queue if a free slot
124123 is immediately available, else raise the Full exception ('timeout'
125124 is ignored in that case).
126- """
125+ '''
127126 with self .not_full :
128127 if self .maxsize > 0 :
129128 if not block :
@@ -146,7 +145,7 @@ def put(self, item, block=True, timeout=None):
146145 self .not_empty .notify ()
147146
148147 def get (self , block = True , timeout = None ):
149- """ Remove and return an item from the queue.
148+ ''' Remove and return an item from the queue.
150149
151150 If optional args 'block' is true and 'timeout' is None (the default),
152151 block if necessary until an item is available. If 'timeout' is
@@ -155,7 +154,7 @@ def get(self, block=True, timeout=None):
155154 Otherwise ('block' is false), return an item if one is immediately
156155 available, else raise the Empty exception ('timeout' is ignored
157156 in that case).
158- """
157+ '''
159158 with self .not_empty :
160159 if not block :
161160 if not self ._qsize ():
@@ -177,19 +176,19 @@ def get(self, block=True, timeout=None):
177176 return item
178177
179178 def put_nowait (self , item ):
180- """ Put an item into the queue without blocking.
179+ ''' Put an item into the queue without blocking.
181180
182181 Only enqueue the item if a free slot is immediately available.
183182 Otherwise raise the Full exception.
184- """
183+ '''
185184 return self .put (item , block = False )
186185
187186 def get_nowait (self ):
188- """ Remove and return an item from the queue without blocking.
187+ ''' Remove and return an item from the queue without blocking.
189188
190189 Only get an item if one is immediately available. Otherwise
191190 raise the Empty exception.
192- """
191+ '''
193192 return self .get (block = False )
194193
195194 # Override these methods to implement other queue organizations
0 commit comments