Skip to content

Commit 99d945c

Browse files
authored
gh-119819: Fix regression to allow logging configuration with multipr… (GH-120030)
1 parent dce14bb commit 99d945c

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

Diff for: Lib/logging/config.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,10 @@ def configure_handler(self, config):
781781
# raise ValueError('No handlers specified for a QueueHandler')
782782
if 'queue' in config:
783783
from multiprocessing.queues import Queue as MPQueue
784+
from multiprocessing import Manager as MM
785+
proxy_queue = MM().Queue()
784786
qspec = config['queue']
785-
if not isinstance(qspec, (queue.Queue, MPQueue)):
787+
if not isinstance(qspec, (queue.Queue, MPQueue, type(proxy_queue))):
786788
if isinstance(qspec, str):
787789
q = self.resolve(qspec)
788790
if not callable(q):

Diff for: Lib/test/test_logging.py

+26
Original file line numberDiff line numberDiff line change
@@ -3926,6 +3926,32 @@ def test_config_queue_handler(self):
39263926
msg = str(ctx.exception)
39273927
self.assertEqual(msg, "Unable to configure handler 'ah'")
39283928

3929+
@unittest.skipIf(support.is_wasi, "WASI does not have multiprocessing.")
3930+
def test_multiprocessing_queues(self):
3931+
# See gh-119819
3932+
cd = copy.deepcopy(self.config_queue_handler)
3933+
from multiprocessing import Queue as MQ, Manager as MM
3934+
q1 = MQ() # this can't be pickled
3935+
q2 = MM().Queue() # a proxy queue for use when pickling is needed
3936+
for qspec in (q1, q2):
3937+
fn = make_temp_file('.log', 'test_logging-cmpqh-')
3938+
cd['handlers']['h1']['filename'] = fn
3939+
cd['handlers']['ah']['queue'] = qspec
3940+
qh = None
3941+
try:
3942+
self.apply_config(cd)
3943+
qh = logging.getHandlerByName('ah')
3944+
self.assertEqual(sorted(logging.getHandlerNames()), ['ah', 'h1'])
3945+
self.assertIsNotNone(qh.listener)
3946+
self.assertIs(qh.queue, qspec)
3947+
self.assertIs(qh.listener.queue, qspec)
3948+
finally:
3949+
h = logging.getHandlerByName('h1')
3950+
if h:
3951+
self.addCleanup(closeFileHandler, h, fn)
3952+
else:
3953+
self.addCleanup(os.remove, fn)
3954+
39293955
def test_90195(self):
39303956
# See gh-90195
39313957
config = {
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)