-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
gh-120868: Fix breaking change in logging.config when using QueueHandler
#120872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
0723f49
afcc79e
08bc4d6
a828c0d
ccc0060
6daf85e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -780,25 +780,37 @@ def configure_handler(self, config): | |
| # 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): | ||
| 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): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Fix a bug in :mod:`logging.config` that would eagerly create an instance of | ||
provinzkraut marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| :class:`multiprocessing.Manager` when configuring a queue_listener with | ||
| :class:`logging.handlers.QueueHandler`. This could cause issue in environments where | ||
| ``multiprocessing.Manager`` does not work. The new implementation will only check for | ||
| these types when it has been verified that ``multiprocessing.Manager`` has been used to | ||
| create the ``queue`` in the logging configuration in question. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Flat is better than nested", so I agree that it's reasonable to rearrange the various tests on
qspecin this way.