pub struct PythonShell { /* private fields */ }Expand description
A persistent python shell over a single wasm guest instance.
Holds the engine’s generic
PersistentInstance so the
guest interpreter’s state survives across calls (the /lang/python/vars/ +
/defs/ semantics depend on this). Each method drives the guest’s py_op ABI via
the generic [PersistentInstance::call_op] and decodes the (tag, payload) reply
into a PyResult.
A PythonShell must be driven from a NON-async thread if its sandbox holds a VFS
capability (the vfs_* host fns blocking_send).
Implementations§
Source§impl PythonShell
impl PythonShell
Sourcepub fn open(sandbox: &Sandbox, per_call_fuel: u64) -> Result<Self>
pub fn open(sandbox: &Sandbox, per_call_fuel: u64) -> Result<Self>
Open a persistent python shell over sandbox.
per_call_fuel is the fuel budget per eval/exec (a fresh budget each call;
the underlying store is reused so the interpreter scope persists).
Sourcepub fn eval(&mut self, expr: &str) -> Result<PyResult>
pub fn eval(&mut self, expr: &str) -> Result<PyResult>
Evaluate an expression -> repr(result) (with \n---\n<stdout> appended if
the expression printed anything), mirroring the /lang/python/eval file.
Sourcepub fn exec(&mut self, src: &str) -> Result<PyResult>
pub fn exec(&mut self, src: &str) -> Result<PyResult>
Execute statements -> captured stdout, mirroring the /lang/python/stdout file.
Sourcepub fn list_vars(&mut self) -> Result<Vec<String>>
pub fn list_vars(&mut self) -> Result<Vec<String>>
Newline-joined non-dunder global variable names (vars/).
Sourcepub fn get_var(&mut self, name: &str) -> Result<PyResult>
pub fn get_var(&mut self, name: &str) -> Result<PyResult>
repr of one global variable (vars/<name>), or None if absent.
Sourcepub fn list_defs(&mut self) -> Result<Vec<String>>
pub fn list_defs(&mut self) -> Result<Vec<String>>
Newline-joined callable global names (defs/).
Sourcepub fn get_def(&mut self, name: &str) -> Result<PyResult>
pub fn get_def(&mut self, name: &str) -> Result<PyResult>
repr of one callable global (defs/<name>), or None if absent/not callable.
Sourcepub fn process_command(&mut self, cmd: PyCommand)
pub fn process_command(&mut self, cmd: PyCommand)
Serve one PyCommand against this shell (runs on the shell-owning thread).
Mirrors TclShell::process_command: the PythonMount forwards each request
over the mount channel; the owner drains the channel and calls this.
Auto Trait Implementations§
impl Freeze for PythonShell
impl !RefUnwindSafe for PythonShell
impl Send for PythonShell
impl !Sync for PythonShell
impl Unpin for PythonShell
impl UnsafeUnpin for PythonShell
impl !UnwindSafe for PythonShell
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self file descriptor.§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more