trader.daemon.signals module¶
Shutdown signalling for the daemon.
A flag rather than an exception raised from the handler: the loop must be allowed to finish the cycle it is in. A KeyboardInterrupt landing between “cancel the protective stop” and “submit the sell” is exactly the interruption this app’s ordering rules exist to prevent.
- class trader.daemon.signals.ShutdownFlag[source]¶
Bases:
objectLatching “stop after this cycle” flag, set from a signal handler.
Latching on purpose: a second SIGTERM must not clear it. An operator pressing Ctrl-C twice means “stop harder”, never “carry on”.
- property reason: str¶
What asked the daemon to stop, for the final log line.
- trader.daemon.signals.install_handlers(flag)[source]¶
Route SIGINT and SIGTERM to flag, returning a restore function.
Returning the restore rather than installing permanently keeps a test process from inheriting the daemon’s handlers, and makes the installation itself assertable.
- Parameters:
flag (ShutdownFlag)
- Return type:
Callable[[], None]