Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Static Private Attributes
logging.handlers.QueueListener Class Reference
Inheritance diagram for logging.handlers.QueueListener:
Inheritance graph
[legend]
Collaboration diagram for logging.handlers.QueueListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def dequeue
def start
def prepare
def handle
def stop

Public Attributes

 queue
 handlers
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Member Functions

def _monitor

Private Attributes

 _stop
 _thread

Static Private Attributes

 _sentinel = None

Detailed Description

This class implements an internal threaded listener which watches for
LogRecords being added to a queue, removes them and passes them to a
list of handlers for processing.

Definition at line 1229 of file handlers.py.


Constructor & Destructor Documentation

def logging.handlers.QueueListener.__init__ (   self,
  queue,
  handlers 
)
Initialise an instance with the specified queue and
handlers.

Definition at line 1237 of file handlers.py.

01237 
01238         def __init__(self, queue, *handlers):
01239             """
01240             Initialise an instance with the specified queue and
01241             handlers.
01242             """
01243             self.queue = queue
01244             self.handlers = handlers
01245             self._stop = threading.Event()
01246             self._thread = None

Here is the caller graph for this function:


Member Function Documentation

def logging.handlers.QueueListener._monitor (   self) [private]
Monitor the queue for records, and ask the handler
to deal with them.

This method runs on a separate, internal thread.
The thread will terminate if it sees a sentinel object in the queue.

Definition at line 1288 of file handlers.py.

01288 
01289         def _monitor(self):
01290             """
01291             Monitor the queue for records, and ask the handler
01292             to deal with them.
01293 
01294             This method runs on a separate, internal thread.
01295             The thread will terminate if it sees a sentinel object in the queue.
01296             """
01297             q = self.queue
01298             has_task_done = hasattr(q, 'task_done')
01299             while not self._stop.isSet():
01300                 try:
01301                     record = self.dequeue(True)
01302                     if record is self._sentinel:
01303                         break
01304                     self.handle(record)
01305                     if has_task_done:
01306                         q.task_done()
01307                 except queue.Empty:
01308                     pass
01309             # There might still be records in the queue.
01310             while True:
01311                 try:
01312                     record = self.dequeue(False)
01313                     if record is self._sentinel:
01314                         break
01315                     self.handle(record)
01316                     if has_task_done:
01317                         q.task_done()
01318                 except queue.Empty:
01319                     break

Here is the call graph for this function:

Here is the caller graph for this function:

def logging.handlers.QueueListener.dequeue (   self,
  block 
)
Dequeue a record and return it, optionally blocking.

The base implementation uses get. You may want to override this method
if you want to use timeouts or work with custom queue implementations.

Definition at line 1247 of file handlers.py.

01247 
01248         def dequeue(self, block):
01249             """
01250             Dequeue a record and return it, optionally blocking.
01251 
01252             The base implementation uses get. You may want to override this method
01253             if you want to use timeouts or work with custom queue implementations.
01254             """
01255             return self.queue.get(block)

Here is the caller graph for this function:

def logging.handlers.QueueListener.handle (   self,
  record 
)
Handle a record.

This just loops through the handlers offering them the record
to handle.

Definition at line 1277 of file handlers.py.

01277 
01278         def handle(self, record):
01279             """
01280             Handle a record.
01281 
01282             This just loops through the handlers offering them the record
01283             to handle.
01284             """
01285             record = self.prepare(record)
01286             for handler in self.handlers:
01287                 handler.handle(record)

Here is the call graph for this function:

Here is the caller graph for this function:

def logging.handlers.QueueListener.prepare (   self,
  record 
)
Prepare a record for handling.

This method just returns the passed-in record. You may want to
override this method if you need to do any custom marshalling or
manipulation of the record before passing it to the handlers.

Definition at line 1267 of file handlers.py.

01267 
01268         def prepare(self , record):
01269             """
01270             Prepare a record for handling.
01271 
01272             This method just returns the passed-in record. You may want to
01273             override this method if you need to do any custom marshalling or
01274             manipulation of the record before passing it to the handlers.
01275             """
01276             return record

Here is the caller graph for this function:

Start the listener.

This starts up a background thread to monitor the queue for
LogRecords to process.

Definition at line 1256 of file handlers.py.

01256 
01257         def start(self):
01258             """
01259             Start the listener.
01260 
01261             This starts up a background thread to monitor the queue for
01262             LogRecords to process.
01263             """
01264             self._thread = t = threading.Thread(target=self._monitor)
01265             t.setDaemon(True)
01266             t.start()

Here is the call graph for this function:

Here is the caller graph for this function:

Stop the listener.

This asks the thread to terminate, and then waits for it to do so.
Note that if you don't call this before your application exits, there
may be some records still left on the queue, which won't be processed.

Definition at line 1320 of file handlers.py.

01320 
01321         def stop(self):
01322             """
01323             Stop the listener.
01324 
01325             This asks the thread to terminate, and then waits for it to do so.
01326             Note that if you don't call this before your application exits, there
01327             may be some records still left on the queue, which won't be processed.
01328             """
01329             self._stop.set()
01330             self.queue.put_nowait(self._sentinel)
01331             self._thread.join()
01332             self._thread = None

Here is the caller graph for this function:


Member Data Documentation

logging.handlers.QueueListener._sentinel = None [static, private]

Definition at line 1235 of file handlers.py.

Definition at line 1244 of file handlers.py.

Definition at line 1245 of file handlers.py.

Definition at line 1243 of file handlers.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 1242 of file handlers.py.


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