[−][src]Function spirit::utils::cleanup_signals
pub fn cleanup_signals()
Remove the signals handling termination.
There's a common pattern of handling termination signals (CTRL+C
, mostly). The first one
initiates a graceful shutdown. But in case the shutdown takes a long time, the user can press
CTRL+C
again and expect to shut down immediately (in more unclean way, possibly).
On the application side, it is handled by resetting the signal handlers to their defaults after
receiving the first one. This can be used to such thing (it resets the signal handlers for
SIGTERM
, SIGINT
, SIGQUIT
).
Warning
This resets the signal handlers, but doesn't remove the hooks. Furthermore, this is a global
action ‒ it doesn't reset only the ones of spirit
, but of everything in the
application.
Also, this example runs the cleanup as part of the normal spirit
background thread. If the
shutdown is being slow (or stuck) in there before calling the on_terminate
here, it won't
have effect. Therefore it is a good idea to register this earlier than later.
Examples
use spirit::{utils, Empty, Spirit}; use spirit::prelude::*; Spirit::<Empty, Empty>::new() .on_terminate(utils::cleanup_signals) .run(|_| { Ok(()) })