-
Notifications
You must be signed in to change notification settings - Fork 763
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
Re-enable recursive class attributes #995
Conversation
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.
Very comprehensive solution, looks great to me! Thanks!
/// 3) if f() does not release the GIL and does not panic, it is guaranteed to be called | ||
/// exactly once, even if multiple threads attempt to call `get_or_init` | ||
/// 4) if f() can panic but still does not release the GIL, it may be called multiple times, | ||
/// but it is guaranteed that f() will never be called concurrently |
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.
👍 nice
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.
Thank you!
}); | ||
|
||
if let Err(err) = result { | ||
err.clone_ref(py).print(py); |
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.
Why we need clone_ref
here?
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.
We only have a &Result<(), PyErr>
, and it seems that PyErr::print
takes self
as an argument, not &self
. So I used clone_ref
(we are in an unlikely error path anyway), but if there is a better way I can change that.
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.
Ah, I see, thanks. Then I think we need clone_ref
.
@scalexm could you also please remove the CHANGELOG entry which I'd previously written about disabling class attributes (as that's now incorrect):
|
Use some kind of two-stage initialization as described in PyO3#975, by being very cautious about when to allow the GIL to be released.
Thank you for the update.
Are you going to push the change to this branch? |
You can merge it, we can do that other change in another PR as it’s not a bug fix but rather a technical improvement. |
Builds on #994 (it's actually the call to
PyType_Modify
through a shared reference which made me realize the problem!).Last thing to do will be to replace
value: GILOnceCell<*mut ffi::PyTypeObject>
withUnsafeCell<ffi::PyTypeObject>
+GILOnceCell<()>
as suggested by @kngwyu.