diff options
author | Janek Nouvertné <provinzkraut@posteo.de> | 2024-06-27 07:09:01 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-27 07:09:01 (GMT) |
commit | 7d9c68513d112823a9a6cdc7453b998b2c24eb4c (patch) | |
tree | 6acf888ef213fd0b83583fcfcd665200d357be1f /Lib/logging | |
parent | 4be1f37b20bd51498d3adf8ad603095c0f38d6e5 (diff) | |
download | cpython-7d9c68513d112823a9a6cdc7453b998b2c24eb4c.zip cpython-7d9c68513d112823a9a6cdc7453b998b2c24eb4c.tar.gz cpython-7d9c68513d112823a9a6cdc7453b998b2c24eb4c.tar.bz2 |
gh-120868: Fix breaking change in `logging.config` when using `QueueHandler` (GH-120872)
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/config.py | 53 |
1 files changed, 36 insertions, 17 deletions
diff --git a/Lib/logging/config.py b/Lib/logging/config.py index d2f23e5..95e129a 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -780,25 +780,44 @@ class DictConfigurator(BaseConfigurator): # if 'handlers' not in config: # raise ValueError('No handlers specified for a QueueHandler') if 'queue' in config: - from multiprocessing.queues import Queue as MPQueue - from multiprocessing import Manager as MM - proxy_queue = MM().Queue() - proxy_joinable_queue = MM().JoinableQueue() qspec = config['queue'] - if not isinstance(qspec, (queue.Queue, MPQueue, - type(proxy_queue), type(proxy_joinable_queue))): - if isinstance(qspec, str): - q = self.resolve(qspec) - if not callable(q): - raise TypeError('Invalid queue specifier %r' % qspec) - q = q() - elif isinstance(qspec, dict): - if '()' not in qspec: - raise TypeError('Invalid queue specifier %r' % qspec) - q = self.configure_custom(dict(qspec)) - else: + + if isinstance(qspec, str): + q = self.resolve(qspec) + if not callable(q): raise TypeError('Invalid queue specifier %r' % qspec) - config['queue'] = q + config['queue'] = q() + elif isinstance(qspec, dict): + if '()' not in qspec: + raise TypeError('Invalid queue specifier %r' % qspec) + config['queue'] = self.configure_custom(dict(qspec)) + else: + from multiprocessing.queues import Queue as MPQueue + + if not isinstance(qspec, (queue.Queue, MPQueue)): + # Safely check if 'qspec' is an instance of Manager.Queue + # / Manager.JoinableQueue + + from multiprocessing import Manager as MM + from multiprocessing.managers import BaseProxy + + # if it's not an instance of BaseProxy, it also can't be + # an instance of Manager.Queue / Manager.JoinableQueue + if isinstance(qspec, BaseProxy): + # Sometimes manager or queue creation might fail + # (e.g. see issue gh-120868). In that case, any + # exception during the creation of these queues will + # propagate up to the caller and be wrapped in a + # `ValueError`, whose cause will indicate the details of + # the failure. + mm = MM() + proxy_queue = mm.Queue() + proxy_joinable_queue = mm.JoinableQueue() + if not isinstance(qspec, (type(proxy_queue), type(proxy_joinable_queue))): + raise TypeError('Invalid queue specifier %r' % qspec) + else: + raise TypeError('Invalid queue specifier %r' % qspec) + if 'listener' in config: lspec = config['listener'] if isinstance(lspec, type): |