8. Signals

Shrapnel provides a way to handle signals. Youn can register a function to receive signals with coro.signal_handler.register().

By default when you start the event loop, two signal handlers are installed (for SIGTERM and SIGINT). The default signal handler will exit the event loop. You can change this behavior by setting coro.install_signal_handlers to False before starting the event loop.

Additionally, there is a signal handler installed for SIGINFO. It prints the name of the coroutine that is currently running. On a typical terminal, you can trigger this with CTRL-T.

coro.signal_handler.register(signum, handler, once_only=False)

Register a signal handler.

Parameters :
  • signum: The signal number to register.
  • handler: A callable object that takes one parameter which is the signal number that was triggered.
  • once_only: If True, will only trigger once, and then disable the signal handler. Defaults to False.
Exceptions :
  • coro.SimultaneousError: Another handler is already registered for this signal.

This Page