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 droppedFields
gstate: PyGILState_STATEpool: ManuallyDrop<Option<GILPool>>_not_send: NotSendImplementations
sourceimpl GILGuard
impl GILGuard
sourcepub fn python(&self) -> Python<'_>
pub fn python(&self) -> Python<'_>
Retrieves the marker type that proves that the GIL was acquired.
sourcepub(crate) fn acquire() -> GILGuard
pub(crate) fn acquire() -> GILGuard
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.
sourcepub(crate) fn acquire_unchecked() -> GILGuard
pub(crate) fn acquire_unchecked() -> GILGuard
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
Auto Trait Implementations
impl RefUnwindSafe for GILGuard
impl !Send for GILGuard
impl !Sync for GILGuard
impl Unpin for GILGuard
impl UnwindSafe for GILGuard
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more