-
Notifications
You must be signed in to change notification settings - Fork 804
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
PyO3 is incompatible with ctypes
#1683
Comments
Hmm. Thank you for reporting, this is 100% a bug in PyO3. For a bit of context of what's going on: we have some internal tracking inside PyO3 which ensures that the user cannot get into unsafety with two particular thorns:
Unfortunately in your example the mitigation we've got in place for the first point is directly clashing with the mitigation for the second point. PyO3 manages these defences by tracking the GIL acquire and release calls internally. It also uses this internal tracking to make some optimizations, e.g. to the implementation of
Unless a way can be found to fix the internal tracking, I guess this implies that it's not sound. Although If it's not sound:
For the foreseeable future, I think that we should document PyO3 is incompatible with We also need to remove a couple of optimizations based on PyO3's internal tracking:
I'll open some issues to track these in the morning. |
... I think if we remove This will take at least a couple of deprecation-and-release cycles to allow the ecosystem to adjust. |
ctypes
Thank you for your help; in my actual use case, the callback isn't called directly by
|
I think depreciating When playing around with cytpes with Rust and PyO3 I ended up having the core functionality be set up agnostic and creating separate public APIs to Ctypes and Pyo3 to avoid crossing between the two bounds. (although I can safely say unless you really, really, really want performance PyPy support Ctypes is considerably more hassle than its worth in a lot of cases. |
I think he meant: deprecate acquire_gil and gilguard, and possibly remove some optimizations in with_gil. |
Yep absolutely. |
Do we want to get rid of |
Yes, especially removing it from examples and the guide would be a great first step towards it's deprecation. Thanks |
For a personal project, I'm trying to provide a Rust callback function to a Python module as a raw function pointer. However, if I attempt to acquire the GIL within the callback function, it causes the program to panic due to out-of-order GIL dropping. As a minimal example:
The program panics before
end callback
can be printed:However, it can clearly be seen that the
GILGuard
s are dropped in the correct order. Is this panic caused by a bug in PyO3, or am I doing something incorrectly?The text was updated successfully, but these errors were encountered: