[3.12] gh-120868: Fix breaking change in `logging.config` when using … · python/cpython@b31f7e2 · GitHub
Skip to content

Commit b31f7e2

Browse files
[3.12] gh-120868: Fix breaking change in logging.config when using QueueHandler (GH-120872) (GH-121077)
(cherry picked from commit 7d9c685)
1 parent 8ea6cc1 commit b31f7e2

3 files changed

Lines changed: 82 additions & 17 deletions

File tree

Lib/logging/config.py

Lines changed: 36 additions & 17 deletions

Lib/test/test_logging.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import weakref
6161

6262
from http.server import HTTPServer, BaseHTTPRequestHandler
63+
from unittest.mock import patch
6364
from urllib.parse import urlparse, parse_qs
6465
from socketserver import (ThreadingUDPServer, DatagramRequestHandler,
6566
ThreadingTCPServer, StreamRequestHandler)
@@ -3895,6 +3896,50 @@ def test_config_queue_handler(self):
38953896
msg = str(ctx.exception)
38963897
self.assertEqual(msg, "Unable to configure handler 'ah'")
38973898

3899+
@threading_helper.requires_working_threading()
3900+
@support.requires_subprocess()
3901+
@patch("multiprocessing.Manager")
3902+
def test_config_queue_handler_does_not_create_multiprocessing_manager(self, manager):
3903+
# gh-120868
3904+
3905+
from multiprocessing import Queue as MQ
3906+
3907+
q1 = {"()": "queue.Queue", "maxsize": -1}
3908+
q2 = MQ()
3909+
q3 = queue.Queue()
3910+
3911+
for qspec in (q1, q2, q3):
3912+
self.apply_config(
3913+
{
3914+
"version": 1,
3915+
"handlers": {
3916+
"queue_listener": {
3917+
"class": "logging.handlers.QueueHandler",
3918+
"queue": qspec,
3919+
},
3920+
},
3921+
}
3922+
)
3923+
manager.assert_not_called()
3924+
3925+
@patch("multiprocessing.Manager")
3926+
def test_config_queue_handler_invalid_config_does_not_create_multiprocessing_manager(self, manager):
3927+
# gh-120868
3928+
3929+
with self.assertRaises(ValueError):
3930+
self.apply_config(
3931+
{
3932+
"version": 1,
3933+
"handlers": {
3934+
"queue_listener": {
3935+
"class": "logging.handlers.QueueHandler",
3936+
"queue": object(),
3937+
},
3938+
},
3939+
}
3940+
)
3941+
manager.assert_not_called()
3942+
38983943
@support.requires_subprocess()
38993944
def test_multiprocessing_queues(self):
39003945
# See gh-119819

Misc/ACKS

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)