Skip to content
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

gh-120868: Fix breaking change in logging.config when using QueueHandler #120872

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

provinzkraut
Copy link
Contributor

@provinzkraut provinzkraut commented Jun 22, 2024

#120868 was caused by an eager construction of multiprocessing.Manager used to check if the queue passed in to the logging config was an instance of multiprocessing.Manager.Queue / multiprocessing.Manager.JoinableQueue. This could cause unexpected exceptions in environments where a multiprocessing.Manager couldn't be created.

The proposed fix moves the check for these classes, and creation of multiprocessing.Manager which is necessary for this, to a point where we've ruled out all other valid options for queue, and are certain that multiprocessing.Manager has been used to produce the object passed via queue.

@provinzkraut provinzkraut requested a review from vsajip as a code owner June 22, 2024 10:30
Copy link

cpython-cla-bot bot commented Jun 22, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

# 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()
Copy link
Member

Choose a reason for hiding this comment

The 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 try-except block? (probably catching an OSError but I'm not sure).

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 TypeError from the error the instantiation raised, but that would still result in roughly the same traceback as when calling .configure, since it already re-raises exceptions.

Or are you suggesting we take a different path here when we encounter an error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I didn't know about the exceptino being wrapped by configure so it may be fine. The thing is, I don't know whether we could be more precise in the error being raised so that you know that's is because multiprocessing queues are not supported.

For instance:

  • you use a bad BaseProxy object which is not a queue and MM().Queue() is fine -> you want the TypeError
  • let's say you have a queue-like object for your readonly system that inherits from MM().Queue() with some tweaks. In this case, you will be able to create your special queue object and expect it to work but MM().Queue() would fail. So instead of having some generic error due to that instantiation, the message could be something else. But I'm not sure whether this corner case is too convoluted or not.

Copy link
Member

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I'm not sure whether this corner case is too convoluted or not.

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 BaseProxy, that allows to perform such checks without creating an instance of the type you want to check against first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Lib/test/test_logging.py Show resolved Hide resolved
q = self.configure_custom(dict(qspec))
else:

if isinstance(qspec, str):
Copy link
Member

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 qspec in this way.

Lib/logging/config.py Outdated Show resolved Hide resolved
@bedevere-app
Copy link

bedevere-app bot commented Jun 22, 2024

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@provinzkraut
Copy link
Contributor Author

Thanks for the review @vsajip!

I have made the requested changes; please review again

:)

@bedevere-app
Copy link

bedevere-app bot commented Jun 23, 2024

Thanks for making the requested changes!

@vsajip: please review the changes made to this pull request.

@bedevere-app bedevere-app bot requested a review from vsajip June 23, 2024 08:11
@vsajip vsajip added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 25, 2024
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @vsajip for commit 6daf85e 🤖

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Jun 25, 2024
Copy link
Member

@vsajip vsajip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some buildbot failures, but they appear unrelated to this change.

@vsajip vsajip merged commit 7d9c685 into python:main Jun 27, 2024
108 of 119 checks passed
@vsajip vsajip added the needs backport to 3.12 bug and security fixes label Jun 27, 2024
@vsajip vsajip added the needs backport to 3.13 bugs and security fixes label Jun 27, 2024
@miss-islington-app
Copy link

Thanks @provinzkraut for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @provinzkraut for the PR, and @vsajip for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 27, 2024
…QueueHandler` (pythonGH-120872)

(cherry picked from commit 7d9c685)

Co-authored-by: Janek Nouvertné <provinzkraut@posteo.de>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 27, 2024
…QueueHandler` (pythonGH-120872)

(cherry picked from commit 7d9c685)

Co-authored-by: Janek Nouvertné <provinzkraut@posteo.de>
@bedevere-app
Copy link

bedevere-app bot commented Jun 27, 2024

GH-121077 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Jun 27, 2024
@bedevere-app
Copy link

bedevere-app bot commented Jun 27, 2024

GH-121078 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Jun 27, 2024
@provinzkraut provinzkraut deleted the fix-gh-120868 branch June 27, 2024 07:35
vsajip pushed a commit that referenced this pull request Jun 27, 2024
vsajip pushed a commit that referenced this pull request Jun 28, 2024
mrahtz pushed a commit to mrahtz/cpython that referenced this pull request Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this pull request Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants