summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/logging/handlers.py2
-rw-r--r--Lib/test/test_logging.py10
-rw-r--r--Misc/NEWS.d/next/Library/2019-05-06-18-28-38.bpo-36813.NXD0KZ.rst2
3 files changed, 14 insertions, 0 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py
index 3727bf0..a913d27 100644
--- a/Lib/logging/handlers.py
+++ b/Lib/logging/handlers.py
@@ -1477,6 +1477,8 @@ class QueueListener(object):
try:
record = self.dequeue(True)
if record is self._sentinel:
+ if has_task_done:
+ q.task_done()
break
self.handle(record)
if has_task_done:
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index b884753..50148dc 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -3633,6 +3633,16 @@ if hasattr(logging.handlers, 'QueueListener'):
[m.msg if isinstance(m, logging.LogRecord)
else m for m in items]))
+ def test_calls_task_done_after_stop(self):
+ # Issue 36813: Make sure queue.join does not deadlock.
+ log_queue = queue.Queue()
+ listener = logging.handlers.QueueListener(log_queue)
+ listener.start()
+ listener.stop()
+ with self.assertRaises(ValueError):
+ # Make sure all tasks are done and .join won't block.
+ log_queue.task_done()
+
ZERO = datetime.timedelta(0)
diff --git a/Misc/NEWS.d/next/Library/2019-05-06-18-28-38.bpo-36813.NXD0KZ.rst b/Misc/NEWS.d/next/Library/2019-05-06-18-28-38.bpo-36813.NXD0KZ.rst
new file mode 100644
index 0000000..e89358a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2019-05-06-18-28-38.bpo-36813.NXD0KZ.rst
@@ -0,0 +1,2 @@
+Fix :class:`~logging.handlers.QueueListener` to call ``queue.task_done()``
+upon stopping. Patch by Bar Harel.