Skip to content
Discussion options

You must be logged in to vote

However, it's not clear how to get the GIL from a function in #[pymthods] or #[pyclass] other than using the deprecated Python::acquire_gil()

There are two answers to this: The replacement for Python::acquire_gil is Python::with_gil which serves the same purpose using a slightly different API (that is easier for us to implement soundly).

However, for #[pyfunction]s and #[pymethod]s, you can just add a parameter py: Python<'_> to get access to the GIL (which is already acquired when such a method is called). Put differently, Python::with_gil is only necessary outside of such Python-visible functions and methods, for example to acquire the GIL on a background thread.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@adamreichold
Comment options

Answer selected by cassc
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants