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: object

Latching “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”.

is_set()[source]

Whether shutdown has been requested.

Return type:

bool

property reason: str

What asked the daemon to stop, for the final log line.

request(signum=None, frame=None)[source]

Request shutdown. Signature matches signal.signal’s handler.

Parameters:
  • signum (int | None)

  • frame (FrameType | None)

Return type:

None

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]