diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-06-01 02:36:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-01 02:36:29 -0700 |
commit | f286e0373feda0955c910a9fe4ef99cd2c40969e (patch) | |
tree | 50a943019b41b88ac3337cab94e898e9482166c6 /Lib | |
parent | 18e23f227be59241cbb1eeb6d6669771dd7275fb (diff) | |
download | cpython-git-f286e0373feda0955c910a9fe4ef99cd2c40969e.tar.gz |
bpo-36813: Fix QueueListener to call task_done() upon termination. (GH-13113)
Fixed QueueListener in order to avoid random deadlocks.
Unable to add regression tests atm due to time constraints, will add it in a bit.
Regarding implementation, although it's nested, it does not cause performance issues whatsoever, and does not call task_done() in case of an exception (which is the right thing to do IMHO).
https://bugs.python.org/issue36813
(cherry picked from commit 6b282e18877ec84e927b381b4ce187eaf4ba3dd7)
Co-authored-by: Bar Harel <bzvi7919@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/logging/handlers.py | 2 | ||||
-rw-r--r-- | Lib/test/test_logging.py | 10 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 3727bf0677..a913d27389 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 d12e1e5745..97c13a4c52 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -3495,6 +3495,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) |