pub struct TerminateOnDrop<O: OutputStream> { /* private fields */ }Expand description
A wrapper that automatically terminates a process when dropped.
§Safety Requirements
WARNING: This type requires a multithreaded tokio runtime to function correctly!
§Usage Guidelines
This type should only be used when:
- Your code is running in a multithreaded tokio runtime.
- Automatic process cleanup on drop is absolutely necessary.
§Recommended Alternatives
Instead of relying on automatic termination, prefer these safer approaches:
- Manual process termination using
ProcessHandle::terminate - Awaiting process completion using
ProcessHandle::wait_for_completion - Awaiting process completion or performing an explicit termination using
ProcessHandle::wait_for_completion_or_terminate
§Implementation Details
The drop implementation tries to terminate the process if it was neither awaited nor terminated before being dropped. If termination fails, a panic is raised.
Methods from Deref<Target = ProcessHandle<O>>§
pub fn id(&self) -> Option<u32>
pub fn is_running(&mut self) -> RunningState
pub fn stdout(&self) -> &O
pub fn stdout_mut(&mut self) -> &mut O
pub fn stderr(&self) -> &O
pub fn stderr_mut(&mut self) -> &mut O
Sourcepub fn must_be_terminated(&mut self)
pub fn must_be_terminated(&mut self)
Sets a panic-on-drop mechanism for this ProcessHandle.
This method enables a safeguard that ensures that the process represented by this
ProcessHandle is properly terminated or awaited before being dropped.
If must_be_terminated is set and the ProcessHandle is
dropped without invoking terminate() or wait(), an intentional panic will occur to
prevent silent failure-states, ensuring that system resources are handled correctly.
You typically do not need to call this, as every ProcessHandle is marked by default.
Call must_not_be_terminated to clear this safeguard to explicitly allow dropping the
process without terminating it.
§Panic
If the ProcessHandle is dropped without being awaited or terminated
after calling this method, a panic will occur with a descriptive message
to inform about the incorrect usage.
pub fn must_not_be_terminated(&mut self)
Sourcepub fn send_interrupt_signal(&mut self) -> Result<(), Error>
pub fn send_interrupt_signal(&mut self) -> Result<(), Error>
Manually sed a SIGINT on unix or equivalent on Windows to this process.
Prefer to call terminate instead, if you want to make sure this process is terminated.
Sourcepub fn send_terminate_signal(&mut self) -> Result<(), Error>
pub fn send_terminate_signal(&mut self) -> Result<(), Error>
Manually sed a SIGTERM on unix or equivalent on Windows to this process.
Prefer to call terminate instead, if you want to make sure this process is terminated.
Sourcepub async fn terminate(
&mut self,
interrupt_timeout: Duration,
terminate_timeout: Duration,
) -> Result<ExitStatus, TerminationError>
pub async fn terminate( &mut self, interrupt_timeout: Duration, terminate_timeout: Duration, ) -> Result<ExitStatus, TerminationError>
Terminates this process by sending a SIGINT, SIGTERM or even a SIGKILL if the process
doesn’t run to completion after receiving any of the first two signals.
pub async fn kill(&mut self) -> Result<()>
Sourcepub async fn wait_for_completion(
&mut self,
timeout: Option<Duration>,
) -> Result<ExitStatus>
pub async fn wait_for_completion( &mut self, timeout: Option<Duration>, ) -> Result<ExitStatus>
Wait for this process to run to completion. Within timeout, if set, or unbound otherwise.