Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf286e03

Browse files
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 commit6b282e1)Co-authored-by: Bar Harel <bzvi7919@gmail.com>
1 parent18e23f2 commitf286e03

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

‎Lib/logging/handlers.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,8 @@ def _monitor(self):
14771477
try:
14781478
record=self.dequeue(True)
14791479
ifrecordisself._sentinel:
1480+
ifhas_task_done:
1481+
q.task_done()
14801482
break
14811483
self.handle(record)
14821484
ifhas_task_done:

‎Lib/test/test_logging.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,6 +3495,16 @@ def test_no_messages_in_queue_after_stop(self):
34953495
[m.msgifisinstance(m,logging.LogRecord)
34963496
elsemforminitems]))
34973497

3498+
deftest_calls_task_done_after_stop(self):
3499+
# Issue 36813: Make sure queue.join does not deadlock.
3500+
log_queue=queue.Queue()
3501+
listener=logging.handlers.QueueListener(log_queue)
3502+
listener.start()
3503+
listener.stop()
3504+
withself.assertRaises(ValueError):
3505+
# Make sure all tasks are done and .join won't block.
3506+
log_queue.task_done()
3507+
34983508

34993509
ZERO=datetime.timedelta(0)
35003510

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix:class:`~logging.handlers.QueueListener` to call ``queue.task_done()``
2+
upon stopping. Patch by Bar Harel.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp