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

refactor PyErr state to reduce blast radius of threading challenge #4650

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

davidhewitt
Copy link
Member

First step towards solving #4584.

Whether we drop the lazy state or not, the first step seems to be to clean up the PyErr implementation so that the location of the threading problem is fully localised within err_state.rs.

I do this by wrapping the UnsafeCell<Option<PyErrState>> as a new PyErrState struct and rename the original state enum to PyErrStateInner. The normal PyErr methods now can't even see the PyErrStateInner enum (and have to go through the .normalized() helper on PyErrState).

This is a pure refactoring without any behaviour changes, we can decide on behaviour changes in future PRs.

@davidhewitt davidhewitt added the CI-skip-changelog Skip checking changelog entry label Oct 25, 2024
Copy link
Contributor

@Icxolu Icxolu left a comment

Choose a reason for hiding this comment

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

Looks good to me!


pub(crate) fn normalize(self, py: Python<'_>) -> PyErrStateNormalized {
impl PyErrStateInner {
pub fn normalize(self, py: Python<'_>) -> PyErrStateNormalized {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason this (and below) switched from pub(crate) to pub?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, just me moving stuff from the outer module and forgetting to adjust visibility. I'll fixup and proceed with merge. Thanks for catching 👍

@davidhewitt davidhewitt enabled auto-merge October 25, 2024 20:48
@davidhewitt davidhewitt added this pull request to the merge queue Oct 25, 2024
Merged via the queue into PyO3:main with commit 5266a72 Oct 25, 2024
44 checks passed
@davidhewitt davidhewitt deleted the err-refactor branch October 25, 2024 21:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI-skip-changelog Skip checking changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants