Skip to main content

Supervisor

Struct Supervisor 

Source
pub struct Supervisor { /* private fields */ }
Expand description

Python 进程的监督者,负责其完整生命周期并转发调用、取消与事件。

通过 Supervisor::new 创建(返回 Arc),Supervisor::start 启动, Supervisor::shutdown 关闭。

Implementations§

Source§

impl Supervisor

Source

pub fn new(config: SupervisorConfig, sink: Arc<dyn EventSink>) -> Arc<Self> ⓘ

创建处于 Status::Starting 的监督者,不会启动进程;需随后调用 Supervisor::start。

Source

pub fn status(&self) -> Status

返回当前状态。

Source

pub fn start(self: &Arc<Self>)

在后台启动 Python 进程并开始监督,立即返回。

只应调用一次:每次调用都会启动一个独立的监督循环;Supervisor::shutdown 之后再调用也 无法重新启动。

Source

pub async fn call( &self, cmd: &str, args: Payload, channels: Vec<(String, ChannelSink)>, opts: CallOptions, ) -> Result<Payload>

调用 Python 命令 cmd,必要时先等待运行时就绪。

运行时处于 Starting 时最多等待 handshake_timeout;调用本身的超时规则见 Bridge::call。

§Errors
  • runtime_unavailable:运行时未就绪、已停止或已崩溃,或等待就绪超时;
  • protocol_mismatch 等:运行时处于 Status::Failed 时返回导致失败的原始错误;
  • runtime_exited:调用进行中 Python 进程退出;
  • 其余错误(invalid_args、timeout、cancelled、frame_too_large、Python 返回的错误等) 见 Bridge::call。
Source

pub fn cancel(&self, window: &str, client_id: &str) -> bool

取消 window 窗口中客户端 id 为 client_id 的调用,返回是否找到该调用。

运行时未运行时仍会让等待者以 cancelled 失败,只是不再通知 Python。详见 Bridge::cancel。

Source

pub fn emit( &self, event: &str, payload: Payload, window: Option<&str>, ) -> Result<()>

向 Python 发送事件,由其 @app.listen(event) 处理;window 为发送方 webview 标签。

不等待运行时就绪,也不等待 Python 处理。

§Errors
  • runtime_unavailable:运行时当前未运行;
  • frame_too_large:事件帧超过大小上限。
Source

pub async fn shutdown(&self)

关闭运行时并等待进程退出,不可逆。

向 Python 发送带 timeoutMs 的 shutdown 帧,由其在该预算内取消进行中的调用并执行 shutdown 钩子;若在 shutdown_timeout 加 1 秒宽限后仍未退出,则强制杀死进程。启动阶段或 重启退避中调用时会直接中止启动;已处于 Crashed / Failed / Stopped 时立即返回。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.