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

Docs: clarify handling of Python references while Rust holds the GIL #1562

Closed
birkenfeld opened this issue Apr 13, 2021 · 3 comments
Closed

Comments

@birkenfeld
Copy link
Member

The relationship between periods holding the GIL and object reference lifetime is not clearly described in the library documentation, leading to bugs like #1547 and #1556. The guide makes a mention in "Advanced topics", but this reads like something that isn't important to know, calling it "invisible".

There should be at least mention in the library reference (maybe just on the topmost level in "Ownership and Lifetimes"?) and also in the guide in a more introductory section.

@davidhewitt
Copy link
Member

Agreed that better documentation is needed here. I'd held off because I kept thinking #1308 was just around the corner, but then I got sidetracked addressing lots of other bugfixes and cleanups.

The worst part of the current system, in my opinion, is that to make it safe PyO3 can only clear the pool on #[pyfunction] return, or when the Python GIL is actually dropped. (It used to be cleared when every GILGuard was dropped, but then it was super trivial to create use-after-free, see #864.) This leads to the extremely long held-object lifetimes which trip users up in #1547 and #1556.

@birkenfeld
Copy link
Member Author

Right, that means that the advice in https://pyo3.rs/v0.13.2/advanced.html isn't actually accurate anymore?

@davidhewitt
Copy link
Member

Closing as the Bound API will replace the GIL Refs discussed here.

@davidhewitt davidhewitt closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants