News for hackers. Stuff that matters.
Re:Calling Rust from Python by guitarbill on Sunday October 08, 2023 @03:51PM (#37813833)
In the example, it isn't used, so AFAIK doesn't acquire the GIL. But that type is used to acquire the GIL explicitly or e.g. import modules.
Re:Calling Rust from Python by ynik on Sunday October 08, 2023 @04:28PM (#37814130)
The Python<'_> type appearing as a parameter means the caller has already acquired the GIL for you. The GIL is held when Python calls into extension modules, and PyO3 doesn't automatically release it (but you can do so yourself).

It's essentially a dummy parameter that serves as proof that the GIL is held. You need to provide it to PyO3 when calling back into the Python runtime, that way the compiler ensures the GIL is still held where required.