Skip to content

Commit 0e150c3

Browse files
[3.12] gh-119819: Fix regression to allow logging configuration with multipr… (GH-120030) (GH-120034)
(cherry picked from commit 99d945c)
1 parent fe68908 commit 0e150c3

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Lib/logging/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,10 @@ def configure_handler(self, config):
788788
# raise ValueError('No handlers specified for a QueueHandler')
789789
if 'queue' in config:
790790
from multiprocessing.queues import Queue as MPQueue
791+
from multiprocessing import Manager as MM
792+
proxy_queue = MM().Queue()
791793
qspec = config['queue']
792-
if not isinstance(qspec, (queue.Queue, MPQueue)):
794+
if not isinstance(qspec, (queue.Queue, MPQueue, type(proxy_queue))):
793795
if isinstance(qspec, str):
794796
q = self.resolve(qspec)
795797
if not callable(q):

Lib/test/test_logging.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3894,6 +3894,32 @@ def test_config_queue_handler(self):
38943894
msg = str(ctx.exception)
38953895
self.assertEqual(msg, "Unable to configure handler 'ah'")
38963896

3897+
@unittest.skipIf(support.is_wasi, "WASI does not have multiprocessing.")
3898+
def test_multiprocessing_queues(self):
3899+
# See gh-119819
3900+
cd = copy.deepcopy(self.config_queue_handler)
3901+
from multiprocessing import Queue as MQ, Manager as MM
3902+
q1 = MQ() # this can't be pickled
3903+
q2 = MM().Queue() # a proxy queue for use when pickling is needed
3904+
for qspec in (q1, q2):
3905+
fn = make_temp_file('.log', 'test_logging-cmpqh-')
3906+
cd['handlers']['h1']['filename'] = fn
3907+
cd['handlers']['ah']['queue'] = qspec
3908+
qh = None
3909+
try:
3910+
self.apply_config(cd)
3911+
qh = logging.getHandlerByName('ah')
3912+
self.assertEqual(sorted(logging.getHandlerNames()), ['ah', 'h1'])
3913+
self.assertIsNotNone(qh.listener)
3914+
self.assertIs(qh.queue, qspec)
3915+
self.assertIs(qh.listener.queue, qspec)
3916+
finally:
3917+
h = logging.getHandlerByName('h1')
3918+
if h:
3919+
self.addCleanup(closeFileHandler, h, fn)
3920+
else:
3921+
self.addCleanup(os.remove, fn)
3922+
38973923
def test_90195(self):
38983924
# See gh-90195
38993925
config = {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix regression to allow logging configuration with multiprocessing queue
2+
types.

0 commit comments

Comments
 (0)