-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
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 1 commit
0723f49
afcc79e
08bc4d6
a828c0d
ccc0060
6daf85e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…ager was created eagerly
- Loading branch information
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() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is an error with the creation, you could maybe wrap that one in an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would we want to behave different in this case? I'm not sure what the expected behaviour would be here. The only thing I could think of that would make sense is to raise the usual Or are you suggesting we take a different path here when we encounter an error?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I didn't know about the exceptino being wrapped by For instance:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think, I'll just leave the decision to Vinay because they're the maintainer and creator of the logging module.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I was worrying about that. I didn't want to put too much stuff in here just to handle this case. IMO the proper proper fix for this would be to add some level of introspection capabilities in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would make sense to add something in the docs for this, as there's quite a few special cases now that might not be immediately intuitive
provinzkraut marked this conversation as resolved.
Outdated
|
||
| 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): | ||
|
|
||
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.