]> granicus.if.org Git - python/commitdiff
Improved QueueListener implementation - queue sentinel addition made extensible.
authorVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 25 Feb 2011 15:56:55 +0000 (15:56 +0000)
committerVinay Sajip <vinay_sajip@yahoo.co.uk>
Fri, 25 Feb 2011 15:56:55 +0000 (15:56 +0000)
Lib/logging/handlers.py

index 96384bd7f7ec67156fbbd3dadaae305b9dcf54ca..57b20576e72286a530cc5847c93068570be4d68d 100644 (file)
@@ -1307,6 +1307,16 @@ class QueueListener(object):
             except queue.Empty:
                 break
 
+    def enqueue_sentinel(self):
+        """
+        This is used to enqueue the sentinel record.
+
+        The base implementation uses put_nowait. You may want to override this
+        method if you want to use timeouts or work with custom queue
+        implementations.
+        """
+        self.queue.put_nowait(self._sentinel)
+
     def stop(self):
         """
         Stop the listener.
@@ -1316,6 +1326,6 @@ class QueueListener(object):
         may be some records still left on the queue, which won't be processed.
         """
         self._stop.set()
-        self.queue.put_nowait(self._sentinel)
+        self.enqueue_sentinel()
         self._thread.join()
         self._thread = None