mirror of https://github.com/python/cpython
gh-119819: Fix regression to allow logging configuration with multipr… (GH-120030)
This commit is contained in:
parent
dce14bb2dc
commit
99d945c0c0
|
@ -781,8 +781,10 @@ class DictConfigurator(BaseConfigurator):
|
||||||
# raise ValueError('No handlers specified for a QueueHandler')
|
# raise ValueError('No handlers specified for a QueueHandler')
|
||||||
if 'queue' in config:
|
if 'queue' in config:
|
||||||
from multiprocessing.queues import Queue as MPQueue
|
from multiprocessing.queues import Queue as MPQueue
|
||||||
|
from multiprocessing import Manager as MM
|
||||||
|
proxy_queue = MM().Queue()
|
||||||
qspec = config['queue']
|
qspec = config['queue']
|
||||||
if not isinstance(qspec, (queue.Queue, MPQueue)):
|
if not isinstance(qspec, (queue.Queue, MPQueue, type(proxy_queue))):
|
||||||
if isinstance(qspec, str):
|
if isinstance(qspec, str):
|
||||||
q = self.resolve(qspec)
|
q = self.resolve(qspec)
|
||||||
if not callable(q):
|
if not callable(q):
|
||||||
|
|
|
@ -3926,6 +3926,32 @@ class ConfigDictTest(BaseTest):
|
||||||
msg = str(ctx.exception)
|
msg = str(ctx.exception)
|
||||||
self.assertEqual(msg, "Unable to configure handler 'ah'")
|
self.assertEqual(msg, "Unable to configure handler 'ah'")
|
||||||
|
|
||||||
|
@unittest.skipIf(support.is_wasi, "WASI does not have multiprocessing.")
|
||||||
|
def test_multiprocessing_queues(self):
|
||||||
|
# See gh-119819
|
||||||
|
cd = copy.deepcopy(self.config_queue_handler)
|
||||||
|
from multiprocessing import Queue as MQ, Manager as MM
|
||||||
|
q1 = MQ() # this can't be pickled
|
||||||
|
q2 = MM().Queue() # a proxy queue for use when pickling is needed
|
||||||
|
for qspec in (q1, q2):
|
||||||
|
fn = make_temp_file('.log', 'test_logging-cmpqh-')
|
||||||
|
cd['handlers']['h1']['filename'] = fn
|
||||||
|
cd['handlers']['ah']['queue'] = qspec
|
||||||
|
qh = None
|
||||||
|
try:
|
||||||
|
self.apply_config(cd)
|
||||||
|
qh = logging.getHandlerByName('ah')
|
||||||
|
self.assertEqual(sorted(logging.getHandlerNames()), ['ah', 'h1'])
|
||||||
|
self.assertIsNotNone(qh.listener)
|
||||||
|
self.assertIs(qh.queue, qspec)
|
||||||
|
self.assertIs(qh.listener.queue, qspec)
|
||||||
|
finally:
|
||||||
|
h = logging.getHandlerByName('h1')
|
||||||
|
if h:
|
||||||
|
self.addCleanup(closeFileHandler, h, fn)
|
||||||
|
else:
|
||||||
|
self.addCleanup(os.remove, fn)
|
||||||
|
|
||||||
def test_90195(self):
|
def test_90195(self):
|
||||||
# See gh-90195
|
# See gh-90195
|
||||||
config = {
|
config = {
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix regression to allow logging configuration with multiprocessing queue
|
||||||
|
types.
|
Loading…
Reference in New Issue