pub struct GracefulShutdown { /* private fields */ }Expand description
Builder and coordinator for graceful shutdown of persistent GPU kernels.
Captures SIGTERM and SIGINT (Ctrl-C), notifies all holders of
ShutdownSignal, waits for a configurable grace period, then
force-terminates.
Implementations§
Source§impl GracefulShutdown
impl GracefulShutdown
Sourcepub fn new(grace_period: Duration) -> Self
pub fn new(grace_period: Duration) -> Self
Create a new shutdown coordinator with the given grace period.
The grace period determines how long ShutdownGuard::wait will
allow after the signal fires before it returns (allowing the caller
to force-terminate remaining work).
Sourcepub fn with_default_grace_period() -> Self
pub fn with_default_grace_period() -> Self
Create a shutdown coordinator with the default grace period (5 seconds).
Sourcepub fn grace_period(&self) -> Duration
pub fn grace_period(&self) -> Duration
Get the configured grace period.
Sourcepub fn is_shutdown_requested(&self) -> bool
pub fn is_shutdown_requested(&self) -> bool
Check if shutdown has already been requested.
Sourcepub fn signal(&self) -> ShutdownSignal
pub fn signal(&self) -> ShutdownSignal
Obtain a ShutdownSignal that can be cloned and distributed to
kernels and background tasks.
Sourcepub fn install(self) -> ShutdownGuard
pub fn install(self) -> ShutdownGuard
Install OS signal handlers and return a ShutdownGuard.
The guard spawns a background task that listens for SIGTERM and
SIGINT (Ctrl-C). When a signal is received the shutdown flag is set
and all ShutdownSignal holders are notified.
Call ShutdownGuard::wait to block until the grace period elapses
after a signal (or until all work completes, whichever comes first).