Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
test.test_queue.FailingQueue Class Reference
Inheritance diagram for test.test_queue.FailingQueue:
Inheritance graph
[legend]
Collaboration diagram for test.test_queue.FailingQueue:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def task_done
def join
def qsize
def empty
def full
def put
def put_nowait
def get
def get_nowait

Public Attributes

 fail_next_put
 fail_next_get
 maxsize
 mutex
 not_empty
 not_full
 all_tasks_done
 unfinished_tasks
 queue

Private Member Functions

def _put
def _get

Detailed Description

Definition at line 247 of file test_queue.py.


Constructor & Destructor Documentation

def test.test_queue.FailingQueue.__init__ (   self,
  args 
)

Reimplemented from queue.Queue.

Definition at line 248 of file test_queue.py.

00248 
00249     def __init__(self, *args):
00250         self.fail_next_put = False
00251         self.fail_next_get = False
        queue.Queue.__init__(self, *args)

Here is the caller graph for this function:


Member Function Documentation

def test.test_queue.FailingQueue._get (   self) [private]

Reimplemented from queue.Queue.

Definition at line 257 of file test_queue.py.

00257 
00258     def _get(self):
00259         if self.fail_next_get:
00260             self.fail_next_get = False
00261             raise FailingQueueException("You Lose")
00262         return queue.Queue._get(self)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_queue.FailingQueue._put (   self,
  item 
) [private]

Reimplemented from queue.Queue.

Definition at line 252 of file test_queue.py.

00252 
00253     def _put(self, item):
00254         if self.fail_next_put:
00255             self.fail_next_put = False
00256             raise FailingQueueException("You Lose")
        return queue.Queue._put(self, item)

Here is the call graph for this function:

def queue.Queue.empty (   self) [inherited]
Return True if the queue is empty, False otherwise (not reliable!).

This method is likely to be removed at some point.  Use qsize() == 0
as a direct substitute, but be aware that either approach risks a race
condition where a queue can grow before the result of empty() or
qsize() can be used.

To create code that needs to wait for all queued tasks to be
completed, the preferred technique is to use the join() method.

Definition at line 93 of file queue.py.

00093 
00094     def empty(self):
00095         """Return True if the queue is empty, False otherwise (not reliable!).
00096 
00097         This method is likely to be removed at some point.  Use qsize() == 0
00098         as a direct substitute, but be aware that either approach risks a race
00099         condition where a queue can grow before the result of empty() or
00100         qsize() can be used.
00101 
00102         To create code that needs to wait for all queued tasks to be
00103         completed, the preferred technique is to use the join() method.
00104 
00105         """
00106         self.mutex.acquire()
00107         n = not self._qsize()
00108         self.mutex.release()
00109         return n

Here is the call graph for this function:

def queue.Queue.full (   self) [inherited]
Return True if the queue is full, False otherwise (not reliable!).

This method is likely to be removed at some point.  Use qsize() >= n
as a direct substitute, but be aware that either approach risks a race
condition where a queue can shrink before the result of full() or
qsize() can be used.

Definition at line 110 of file queue.py.

00110 
00111     def full(self):
00112         """Return True if the queue is full, False otherwise (not reliable!).
00113 
00114         This method is likely to be removed at some point.  Use qsize() >= n
00115         as a direct substitute, but be aware that either approach risks a race
00116         condition where a queue can shrink before the result of full() or
00117         qsize() can be used.
00118 
00119         """
00120         self.mutex.acquire()
00121         n = 0 < self.maxsize <= self._qsize()
00122         self.mutex.release()
00123         return n

Here is the call graph for this function:

def queue.Queue.get (   self,
  block = True,
  timeout = None 
) [inherited]
Remove and return an item from the queue.

If optional args 'block' is true and 'timeout' is None (the default),
block if necessary until an item is available. If 'timeout' is
a positive number, it blocks at most 'timeout' seconds and raises
the Empty exception if no item was available within that time.
Otherwise ('block' is false), return an item if one is immediately
available, else raise the Empty exception ('timeout' is ignored
in that case).

Definition at line 167 of file queue.py.

00167 
00168     def get(self, block=True, timeout=None):
00169         """Remove and return an item from the queue.
00170 
00171         If optional args 'block' is true and 'timeout' is None (the default),
00172         block if necessary until an item is available. If 'timeout' is
00173         a positive number, it blocks at most 'timeout' seconds and raises
00174         the Empty exception if no item was available within that time.
00175         Otherwise ('block' is false), return an item if one is immediately
00176         available, else raise the Empty exception ('timeout' is ignored
00177         in that case).
00178         """
00179         self.not_empty.acquire()
00180         try:
00181             if not block:
00182                 if not self._qsize():
00183                     raise Empty
00184             elif timeout is None:
00185                 while not self._qsize():
00186                     self.not_empty.wait()
00187             elif timeout < 0:
00188                 raise ValueError("'timeout' must be a positive number")
00189             else:
00190                 endtime = _time() + timeout
00191                 while not self._qsize():
00192                     remaining = endtime - _time()
00193                     if remaining <= 0.0:
00194                         raise Empty
00195                     self.not_empty.wait(remaining)
00196             item = self._get()
00197             self.not_full.notify()
00198             return item
00199         finally:
00200             self.not_empty.release()

Here is the call graph for this function:

Here is the caller graph for this function:

def queue.Queue.get_nowait (   self) [inherited]
Remove and return an item from the queue without blocking.

Only get an item if one is immediately available. Otherwise
raise the Empty exception.

Definition at line 201 of file queue.py.

00201 
00202     def get_nowait(self):
00203         """Remove and return an item from the queue without blocking.
00204 
00205         Only get an item if one is immediately available. Otherwise
00206         raise the Empty exception.
00207         """
00208         return self.get(False)

Here is the call graph for this function:

def queue.Queue.join (   self) [inherited]
Blocks until all items in the Queue have been gotten and processed.

The count of unfinished tasks goes up whenever an item is added to the
queue. The count goes down whenever a consumer thread calls task_done()
to indicate the item was retrieved and all work on it is complete.

When the count of unfinished tasks drops to zero, join() unblocks.

Definition at line 70 of file queue.py.

00070 
00071     def join(self):
00072         """Blocks until all items in the Queue have been gotten and processed.
00073 
00074         The count of unfinished tasks goes up whenever an item is added to the
00075         queue. The count goes down whenever a consumer thread calls task_done()
00076         to indicate the item was retrieved and all work on it is complete.
00077 
00078         When the count of unfinished tasks drops to zero, join() unblocks.
00079         """
00080         self.all_tasks_done.acquire()
00081         try:
00082             while self.unfinished_tasks:
00083                 self.all_tasks_done.wait()
00084         finally:
00085             self.all_tasks_done.release()

Here is the caller graph for this function:

def queue.Queue.put (   self,
  item,
  block = True,
  timeout = None 
) [inherited]
Put an item into the queue.

If optional args 'block' is true and 'timeout' is None (the default),
block if necessary until a free slot is available. If 'timeout' is
a positive number, it blocks at most 'timeout' seconds and raises
the Full exception if no free slot was available within that time.
Otherwise ('block' is false), put an item on the queue if a free slot
is immediately available, else raise the Full exception ('timeout'
is ignored in that case).

Definition at line 124 of file queue.py.

00124 
00125     def put(self, item, block=True, timeout=None):
00126         """Put an item into the queue.
00127 
00128         If optional args 'block' is true and 'timeout' is None (the default),
00129         block if necessary until a free slot is available. If 'timeout' is
00130         a positive number, it blocks at most 'timeout' seconds and raises
00131         the Full exception if no free slot was available within that time.
00132         Otherwise ('block' is false), put an item on the queue if a free slot
00133         is immediately available, else raise the Full exception ('timeout'
00134         is ignored in that case).
00135         """
00136         self.not_full.acquire()
00137         try:
00138             if self.maxsize > 0:
00139                 if not block:
00140                     if self._qsize() >= self.maxsize:
00141                         raise Full
00142                 elif timeout is None:
00143                     while self._qsize() >= self.maxsize:
00144                         self.not_full.wait()
00145                 elif timeout < 0:
00146                     raise ValueError("'timeout' must be a positive number")
00147                 else:
00148                     endtime = _time() + timeout
00149                     while self._qsize() >= self.maxsize:
00150                         remaining = endtime - _time()
00151                         if remaining <= 0.0:
00152                             raise Full
00153                         self.not_full.wait(remaining)
00154             self._put(item)
00155             self.unfinished_tasks += 1
00156             self.not_empty.notify()
00157         finally:
00158             self.not_full.release()

Here is the call graph for this function:

Here is the caller graph for this function:

def queue.Queue.put_nowait (   self,
  item 
) [inherited]
Put an item into the queue without blocking.

Only enqueue the item if a free slot is immediately available.
Otherwise raise the Full exception.

Definition at line 159 of file queue.py.

00159 
00160     def put_nowait(self, item):
00161         """Put an item into the queue without blocking.
00162 
00163         Only enqueue the item if a free slot is immediately available.
00164         Otherwise raise the Full exception.
00165         """
00166         return self.put(item, False)

Here is the call graph for this function:

def queue.Queue.qsize (   self) [inherited]
Return the approximate size of the queue (not reliable!).

Definition at line 86 of file queue.py.

00086 
00087     def qsize(self):
00088         """Return the approximate size of the queue (not reliable!)."""
00089         self.mutex.acquire()
00090         n = self._qsize()
00091         self.mutex.release()
00092         return n

Here is the call graph for this function:

def queue.Queue.task_done (   self) [inherited]
Indicate that a formerly enqueued task is complete.

Used by Queue consumer threads.  For each get() used to fetch a task,
a subsequent call to task_done() tells the queue that the processing
on the task is complete.

If a join() is currently blocking, it will resume when all items
have been processed (meaning that a task_done() call was received
for every item that had been put() into the queue).

Raises a ValueError if called more times than there were items
placed in the queue.

Definition at line 45 of file queue.py.

00045 
00046     def task_done(self):
00047         """Indicate that a formerly enqueued task is complete.
00048 
00049         Used by Queue consumer threads.  For each get() used to fetch a task,
00050         a subsequent call to task_done() tells the queue that the processing
00051         on the task is complete.
00052 
00053         If a join() is currently blocking, it will resume when all items
00054         have been processed (meaning that a task_done() call was received
00055         for every item that had been put() into the queue).
00056 
00057         Raises a ValueError if called more times than there were items
00058         placed in the queue.
00059         """
00060         self.all_tasks_done.acquire()
00061         try:
00062             unfinished = self.unfinished_tasks - 1
00063             if unfinished <= 0:
00064                 if unfinished < 0:
00065                     raise ValueError('task_done() called too many times')
00066                 self.all_tasks_done.notify_all()
00067             self.unfinished_tasks = unfinished
00068         finally:
00069             self.all_tasks_done.release()


Member Data Documentation

Definition at line 42 of file queue.py.

Definition at line 250 of file test_queue.py.

Definition at line 249 of file test_queue.py.

queue.Queue.maxsize [inherited]

Definition at line 27 of file queue.py.

queue.Queue.mutex [inherited]

Definition at line 33 of file queue.py.

queue.Queue.not_empty [inherited]

Definition at line 36 of file queue.py.

queue.Queue.not_full [inherited]

Definition at line 39 of file queue.py.

queue.Queue.queue [inherited]

Reimplemented in queue.LifoQueue, and queue.PriorityQueue.

Definition at line 215 of file queue.py.

Definition at line 43 of file queue.py.


The documentation for this class was generated from the following file: