⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here
pub struct GILGuard {
    gstate: PyGILState_STATE,
    pool: ManuallyDrop<Option<GILPool>>,
    _not_send: NotSend,
}
Expand description

RAII type that represents the Global Interpreter Lock acquisition.

Users are strongly encouraged to use Python::with_gil instead of directly constructing this type. See Python::acquire_gil for more.

Examples

use pyo3::Python;

{
    let gil_guard = Python::acquire_gil();
    let py = gil_guard.python();
} // GIL is released when gil_guard is dropped

Fields

gstate: PyGILState_STATEpool: ManuallyDrop<Option<GILPool>>_not_send: NotSend

Implementations

Retrieves the marker type that proves that the GIL was acquired.

PyO3 internal API for acquiring the GIL. The public API is Python::acquire_gil.

If PyO3 does not yet have a GILPool for tracking owned PyObject references, then this new GILGuard will also contain a GILPool.

Acquires the GILGuard without performing any state checking.

This can be called in “unsafe” contexts where the normal interpreter state checking performed by GILGuard::acquire may fail. This includes calling as part of multi-phase interpreter initialization.

Trait Implementations

The Drop implementation for GILGuard will release the GIL.

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.