Struct pyembed::MainPythonInterpreter [−][src]
Manages an embedded Python interpreter.
Python interpreters have global state and there can only be a single
instance of this type per process. There exists a global lock enforcing
this. Calling new() will block waiting for this lock. The lock is
released when the instance is dropped.
Instances must only be constructed through MainPythonInterpreter::new().
This type and its various functionality is a glorified wrapper around the Python C API. But there’s a lot of added functionality on top of what the C API provides.
Both the low-level python3-sys and higher-level cpython crates are used.
Implementations
impl<'python, 'interpreter, 'resources> MainPythonInterpreter<'python, 'interpreter, 'resources>[src]
pub fn new(
config: OxidizedPythonInterpreterConfig<'resources>
) -> Result<MainPythonInterpreter<'python, 'interpreter, 'resources>, NewInterpreterError>[src]
config: OxidizedPythonInterpreterConfig<'resources>
) -> Result<MainPythonInterpreter<'python, 'interpreter, 'resources>, NewInterpreterError>
Construct a Python interpreter from a configuration.
The Python interpreter is initialized as a side-effect. The GIL is held.
pub fn release_gil(&mut self)[src]
Ensure the Python GIL is released.
pub fn acquire_gil(&mut self) -> Python<'_>[src]
Ensure the Python GIL is acquired, returning a handle on the interpreter.
The returned value has a lifetime of the MainPythonInterpreter
instance. This is because MainPythonInterpreter.drop() finalizes
the interpreter. The borrow checker should refuse to compile code
where the returned Python outlives self.
pub fn py_runmain(self) -> i32[src]
Runs Py_RunMain() and finalizes the interpreter.
This will execute whatever is configured by the Python interpreter config and return an integer suitable for use as a process exit code.
Calling this function will finalize the interpreter and only gives you an exit code: there is no opportunity to inspect the return value or handle an uncaught exception. If you want to keep the interpreter alive or inspect the evaluation result, consider calling a function on the interpreter handle that executes code.
Trait Implementations
impl<'python, 'interpreter, 'resources> Drop for MainPythonInterpreter<'python, 'interpreter, 'resources>[src]
Auto Trait Implementations
impl<'python, 'interpreter, 'resources> !RefUnwindSafe for MainPythonInterpreter<'python, 'interpreter, 'resources>
impl<'python, 'interpreter, 'resources> !Send for MainPythonInterpreter<'python, 'interpreter, 'resources>
impl<'python, 'interpreter, 'resources> !Sync for MainPythonInterpreter<'python, 'interpreter, 'resources>
impl<'python, 'interpreter, 'resources> Unpin for MainPythonInterpreter<'python, 'interpreter, 'resources>
impl<'python, 'interpreter, 'resources> !UnwindSafe for MainPythonInterpreter<'python, 'interpreter, 'resources>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,