-
Notifications
You must be signed in to change notification settings - Fork 770
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
Is this „nasty“ code around GIL sound? #1019
Comments
Interesting, thank you for reporting.
I understand the problem but now I have no idea to fix this 🤔
I think we can handle the situation better by using |
If we're expecting the upcoming Python limited API to make structs opaque, it may not be a good idea to rely on the internals of
I think I can put together a test case - will report back. |
Ok, after my simple fix failed I think that we cannot safely allow return of a
I see three possible solutions. Which do you guys think is best?
As (3) is overly restrictive in my opinion, I think (2) is probably best. I've got to dash now, so I will put together the test for |
I don't know if the I was also thinking if changing the GILGuard::with(|guard: &GILGuard| {
...
}) (And one would newer be able to get hold of the That would make sure one can't do ugly things like pass it around through other GIL guards, reorder their drops, store it for later in a structure or |
That's really appealing to me, though it can require lots of code changes in user codes... 🤔 |
Would some kind of deprecation notice/transition period help smooth that out? Eg: impl GILGuard {
#[doc(hidden)]
#[deprecated(message = "Use GILGuard::with instead, this one is broken and will be removed in next major version")]
pub fn acquire() -> Self {
...
}
pub fn with<T, F: FnOnce(&GILGuard) -> T>(f: F) -> T {
...
}
} |
I really love this proposal! Though I think we might be able to go further and make
Deprecation notice on |
Would it be possible to solve the |
I wrote this test for
Yeah you're probably right, we could avoid breaking user code. All documentation could change to use We can fix For
I'd be tempted to go for (2) here. It will cause occasional surprises, but I'm not 100% confident (1) will not have other edge cases and it probably is higher overhead. |
Hello
When reading through the docs, I sometimes have the habit of clicking on the
[src]
button and looking under the hood. And I've come up with some code I'm not sure is not UB (besides me not using unsafe). It might be fine, but I think it makes sense to share it and ask why it is fine.The thing I worry about the
cross_release
is, the documentation forPyGILState_Ensure
seems to hint (not very explicitly) that the correspondingPyGILState_Release
should be called in reverse order:If taken literally, the interpreter should be left in the state after acquiring
g1
, because it's the state it should return to after releasingg2
. I don't know how to „prove“ anything wrong is happening, though, I haven't seen anything weird manifest.The
messed_gil_cnt
is similar, but I've noticed one further problem. When I'm looking at the source code here: https://docs.rs/pyo3/0.11.1/src/pyo3/python.rs.html#129-150, I think this is happening:GIL_COUNT
set to some unknownn
.GIL_COUNT
is set to 0.GIL_COUNT
to1
. Furthermore, as it is 0, it creates theGILPool
(because thegil_is_acquired
works based on theGIL_COUNT
, https://docs.rs/pyo3/0.11.1/src/pyo3/gil.rs.html#167), but at least the comment above says there should not be two pools on the same thread.GIL_COUNT
is reset back ton
, losing the one from the createdGILGuard
I don't know if it is related, but the code deadlocks, it never prints
Returned
.The text was updated successfully, but these errors were encountered: