mirror of
https://github.com/python/cpython.git
synced 2025-10-03 05:35:59 +00:00
[3.12] gh-111615: Fix regression in QueueHandler configuration. (GH-111638) (GH-113507)
This commit is contained in:
parent
6177a852c4
commit
ba3e19a5d7
3 changed files with 40 additions and 17 deletions
|
@ -1,4 +1,4 @@
|
||||||
# Copyright 2001-2022 by Vinay Sajip. All Rights Reserved.
|
# Copyright 2001-2023 by Vinay Sajip. All Rights Reserved.
|
||||||
#
|
#
|
||||||
# Permission to use, copy, modify, and distribute this software and its
|
# Permission to use, copy, modify, and distribute this software and its
|
||||||
# documentation for any purpose and without fee is hereby granted,
|
# documentation for any purpose and without fee is hereby granted,
|
||||||
|
@ -740,7 +740,7 @@ class DictConfigurator(BaseConfigurator):
|
||||||
lklass = kwargs['listener']
|
lklass = kwargs['listener']
|
||||||
else:
|
else:
|
||||||
lklass = logging.handlers.QueueListener
|
lklass = logging.handlers.QueueListener
|
||||||
listener = lklass(q, *kwargs['handlers'], respect_handler_level=rhl)
|
listener = lklass(q, *kwargs.get('handlers', []), respect_handler_level=rhl)
|
||||||
handler = klass(q)
|
handler = klass(q)
|
||||||
handler.listener = listener
|
handler.listener = listener
|
||||||
return handler
|
return handler
|
||||||
|
@ -782,11 +782,12 @@ class DictConfigurator(BaseConfigurator):
|
||||||
raise ValueError('Unable to set target handler %r' % tn) from e
|
raise ValueError('Unable to set target handler %r' % tn) from e
|
||||||
elif issubclass(klass, logging.handlers.QueueHandler):
|
elif issubclass(klass, logging.handlers.QueueHandler):
|
||||||
# Another special case for handler which refers to other handlers
|
# Another special case for handler which refers to other handlers
|
||||||
if 'handlers' not in config:
|
# if 'handlers' not in config:
|
||||||
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
|
||||||
qspec = config['queue']
|
qspec = config['queue']
|
||||||
if not isinstance(qspec, queue.Queue):
|
if not isinstance(qspec, (queue.Queue, MPQueue)):
|
||||||
if isinstance(qspec, str):
|
if isinstance(qspec, str):
|
||||||
q = self.resolve(qspec)
|
q = self.resolve(qspec)
|
||||||
if not callable(q):
|
if not callable(q):
|
||||||
|
@ -819,18 +820,19 @@ class DictConfigurator(BaseConfigurator):
|
||||||
if not callable(listener):
|
if not callable(listener):
|
||||||
raise TypeError('Invalid listener specifier %r' % lspec)
|
raise TypeError('Invalid listener specifier %r' % lspec)
|
||||||
config['listener'] = listener
|
config['listener'] = listener
|
||||||
hlist = []
|
if 'handlers' in config:
|
||||||
try:
|
hlist = []
|
||||||
for hn in config['handlers']:
|
try:
|
||||||
h = self.config['handlers'][hn]
|
for hn in config['handlers']:
|
||||||
if not isinstance(h, logging.Handler):
|
h = self.config['handlers'][hn]
|
||||||
config.update(config_copy) # restore for deferred cfg
|
if not isinstance(h, logging.Handler):
|
||||||
raise TypeError('Required handler %r '
|
config.update(config_copy) # restore for deferred cfg
|
||||||
'is not configured yet' % hn)
|
raise TypeError('Required handler %r '
|
||||||
hlist.append(h)
|
'is not configured yet' % hn)
|
||||||
except Exception as e:
|
hlist.append(h)
|
||||||
raise ValueError('Unable to set required handler %r' % hn) from e
|
except Exception as e:
|
||||||
config['handlers'] = hlist
|
raise ValueError('Unable to set required handler %r' % hn) from e
|
||||||
|
config['handlers'] = hlist
|
||||||
elif issubclass(klass, logging.handlers.SMTPHandler) and\
|
elif issubclass(klass, logging.handlers.SMTPHandler) and\
|
||||||
'mailhost' in config:
|
'mailhost' in config:
|
||||||
config['mailhost'] = self.as_tuple(config['mailhost'])
|
config['mailhost'] = self.as_tuple(config['mailhost'])
|
||||||
|
|
|
@ -3892,6 +3892,25 @@ class ConfigDictTest(BaseTest):
|
||||||
# Logger should be enabled, since explicitly mentioned
|
# Logger should be enabled, since explicitly mentioned
|
||||||
self.assertFalse(logger.disabled)
|
self.assertFalse(logger.disabled)
|
||||||
|
|
||||||
|
def test_111615(self):
|
||||||
|
# See gh-111615
|
||||||
|
import multiprocessing as mp
|
||||||
|
|
||||||
|
config = {
|
||||||
|
'version': 1,
|
||||||
|
'handlers': {
|
||||||
|
'sink': {
|
||||||
|
'class': 'logging.handlers.QueueHandler',
|
||||||
|
'queue': mp.get_context('spawn').Queue(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
'root': {
|
||||||
|
'handlers': ['sink'],
|
||||||
|
'level': 'DEBUG',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
logging.config.dictConfig(config)
|
||||||
|
|
||||||
class ManagerTest(BaseTest):
|
class ManagerTest(BaseTest):
|
||||||
def test_manager_loggerclass(self):
|
def test_manager_loggerclass(self):
|
||||||
logged = []
|
logged = []
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix a regression caused by a fix to gh-93162 whereby you couldn't configure
|
||||||
|
a :class:`QueueHandler` without specifying handlers.
|
Loading…
Add table
Add a link
Reference in a new issue