Trait process_control::Control
source · pub trait Control: Sealed {
type Result;
// Required methods
fn memory_limit(self, limit: usize) -> Self;
fn time_limit(self, limit: Duration) -> Self;
fn strict_errors(self) -> Self;
fn terminate_for_timeout(self) -> Self;
fn wait(self) -> Result<Option<Self::Result>>;
}
Expand description
A temporary wrapper for process limits.
Required Associated Types§
Required Methods§
sourcefn memory_limit(self, limit: usize) -> Self
fn memory_limit(self, limit: usize) -> Self
Sets the total virtual memory limit for the process in bytes.
If the process attempts to allocate memory in excess of this limit, the allocation will fail. The type of failure will depend on the platform, and the process might terminate if it cannot handle it.
Small memory limits are safe, but they might prevent the operating system from starting the process.
sourcefn time_limit(self, limit: Duration) -> Self
fn time_limit(self, limit: Duration) -> Self
Sets the total time limit for the process in milliseconds.
A process that exceeds this limit will not be terminated unless
terminate_for_timeout
is called.
sourcefn strict_errors(self) -> Self
fn strict_errors(self) -> Self
Causes wait
to never suppress an error.
Typically, errors terminating the process will be ignored, as they are often less important than the result. However, when this method is called, those errors will be returned as well.
sourcefn terminate_for_timeout(self) -> Self
fn terminate_for_timeout(self) -> Self
Causes the process to be terminated if it exceeds the time limit.
Process identifier reuse by the system will be mitigated. There should never be a scenario that causes an unintended process to be terminated.
sourcefn wait(self) -> Result<Option<Self::Result>>
fn wait(self) -> Result<Option<Self::Result>>
Runs the process to completion, aborting if it exceeds the time limit.
At least one additional thread might be created to wait on the process without blocking the current thread.
If the time limit is exceeded before the process finishes, Ok(None)
will be returned. However, the process will not be terminated in that
case unless terminate_for_timeout
is called beforehand. It is
recommended to always call that method to allow system resources to be
freed.
The stdin handle to the process, if it exists, will be closed before waiting. Otherwise, the process would assuredly time out when reading from that pipe.
This method cannot guarantee that the same io::ErrorKind
variants
will be returned in the future for the same types of failures. Allowing
these breakages is required to enable calling Child::kill
internally.