Struct cpython::Python [−][src]
pub struct Python<'p>(_);
Marker type that indicates that the GIL is currently held.
The 'Python' struct is a zero-size marker struct that is required for most Python operations.
This is used to indicate that the operation accesses/modifies the Python interpreter state,
and thus can only be called if the Python interpreter is initialized and the
Python global interpreter lock (GIL) is acquired.
The lifetime 'p
represents the lifetime of the Python interpreter.
You can imagine the GIL to be a giant Mutex<PythonInterpreterState>
.
The type Python<'p>
then acts like a reference &'p PythonInterpreterState
.
Methods
impl<'p> Python<'p>
[src]
impl<'p> Python<'p>
pub unsafe fn assume_gil_acquired() -> Python<'p>
[src]
pub unsafe fn assume_gil_acquired() -> Python<'p>
Retrieve Python instance under the assumption that the GIL is already acquired at this point,
and stays acquired for the lifetime 'p
.
Because the output lifetime 'p
is not connected to any input parameter,
care must be taken that the compiler infers an appropriate lifetime for 'p
when calling this function.
pub fn acquire_gil() -> GILGuard
[src]
pub fn acquire_gil() -> GILGuard
Acquires the global interpreter lock, which allows access to the Python runtime.
If the Python runtime is not already initialized, this function will initialize it. See prepare_freethreaded_python() for details.
pub fn allow_threads<T, F>(self, f: F) -> T where
F: Send + FnOnce() -> T,
[src]
pub fn allow_threads<T, F>(self, f: F) -> T where
F: Send + FnOnce() -> T,
Temporarily releases the GIL, thus allowing other Python threads to run.
pub fn eval(
self,
code: &str,
globals: Option<&PyDict>,
locals: Option<&PyDict>
) -> PyResult<PyObject>
[src]
pub fn eval(
self,
code: &str,
globals: Option<&PyDict>,
locals: Option<&PyDict>
) -> PyResult<PyObject>
Evaluates a Python expression in the given context and returns the result.
If globals
is None
, it defaults to Python module __main__
.
If locals
is None
, it defaults to the value of globals
.
pub fn run(
self,
code: &str,
globals: Option<&PyDict>,
locals: Option<&PyDict>
) -> PyResult<()>
[src]
pub fn run(
self,
code: &str,
globals: Option<&PyDict>,
locals: Option<&PyDict>
) -> PyResult<()>
Executes one or more Python statements in the given context.
If globals
is None
, it defaults to Python module __main__
.
If locals
is None
, it defaults to the value of globals
.
pub fn None(self) -> PyObject
[src]
pub fn None(self) -> PyObject
Gets the Python builtin value None
.
pub fn True(self) -> PyBool
[src]
pub fn True(self) -> PyBool
Gets the Python builtin value True
.
pub fn False(self) -> PyBool
[src]
pub fn False(self) -> PyBool
Gets the Python builtin value False
.
pub fn NotImplemented(self) -> PyObject
[src]
pub fn NotImplemented(self) -> PyObject
Gets the Python builtin value NotImplemented
.
pub fn get_type<T>(self) -> PyType where
T: PythonObjectWithTypeObject,
[src]
pub fn get_type<T>(self) -> PyType where
T: PythonObjectWithTypeObject,
Gets the Python type object for type T.
pub fn import(self, name: &str) -> PyResult<PyModule>
[src]
pub fn import(self, name: &str) -> PyResult<PyModule>
Import the Python module with the specified name.