-
Notifications
You must be signed in to change notification settings - Fork 758
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
Documentaion about when we free memory #311
Comments
Probably 'freed-after-drop' can cause slowness. I suppose it would be fine to free mem by calling something like gil.clear() manually sometimes. |
I agree that we should improve the documentation, we especially need need a proper explanation of our GC interacting types in the guide.
It would be possible with a
|
I found loop {
let _pool = pyo3::GILPool::new();
...
} also works to decrease ref counts. |
Wait a minute. Since anyone can create and drop a new Proposed fix: #585. |
I don't think so. |
And what if there are Python objects in the pool? We could be calling it from another thread, exposing us to all kinds of race conditions. Or, we could have leaked a previous |
Requiring |
I’m not sure which part is unclear, so I’ll try to spell it out (sorry if I’m repeating the obvious):
Part of what makes Rust Rust is that it should not be possible, under any circumstances, to trigger undefined behavior in code that does not explicitly use an Thus, when this code leads to undefined behavior, it’s PyO3’s fault: thread::spawn(|| {
drop(pyo3::GILPool::new());
}) But when this code leads to undefined behavior, it’s clearly the user’s fault. thread::spawn(|| {
let py = unsafe { pyo3::Python::assume_gil_acquired() };
drop(pyo3::GILPool::new(py));
}) Makes sense? |
Thank you for your explanation, but I'm still not sure how GILPool behaves in multithread situation 🤔 (actually the indices it has can cause problems, even if GIL is correctly acquired). |
This was closed by #893, which closed a soundness hole in Would there be interest in a PR to include some examples like these in the guide and possibly adding more breadcrumbs to the API documentation for |
New documentation is always welcome and appreciated. I never got around to writing more because I really do want to explore better ways to do this soon. (see #1308) I think at this point it's not realistically on the cards as something I'll tackle in 0.15, so additional documentation will be valuable for users for at least one release cycle. And most likely when writing changes I'll iterate on existing docs rather than throw them away. |
* Improve API docs regarding when we free memory, resolves #311 * Add chapter to guide about when we free memory, resolves #311 * Fix typos in documentation Co-authored-by: David Hewitt <[email protected]> * Add links from guide to docs.rs * Update guide/src/memory.md Co-authored-by: David Hewitt <[email protected]>
I got an issue in rust-numpy repo today.
See the below code:
In such a case, I think most users assume that
py_arr
is freed when an iteration of the loop ends, but truly, it's freed afterGILGuard
drops.So my suggestions are:
GILGuard
dropsThe text was updated successfully, but these errors were encountered: