saturnin.lib.daemon

Saturnin daemon process management.

Functions

saturnin.lib.daemon.start_daemon(args: List[str]) int | None[source]

Starts daemon process.

Parameters:

args (List[str]) – Arguments for subprocess.Popen (first item must be the daemon filename)

Returns:

PID for started daemon, or None if start failed.

Return type:

int | None

Note

Gracefull shutdown on Windows is tricky. To allow shutdown of daemon process via SIGINT signal handler (note that SIGINT is not available on Windows, you have to send CTRL_C_EVENT), it’s necessry to start new shell with new console in background.

saturnin.lib.daemon.stop_daemon(pid: int | str | Path) None[source]

Stops the daemon process by invoking saturnin-daemon script.

Parameters:

pid (int | str | Path) – PID or text file name/Path where PID is stored.

Raises:
Return type:

None

Important

On Linux/Unix: Sends SIGINT signal to the daemon process. On Windows: Detaches from console, attaches itself to daemon console and sends control-C event to it.

Note

Gracefull shutdown on Windows is tricky. It requires that the daemon process has a console, otherwise the CTRL_C_EVENT couldn’t be delivered. This condition is met if daemon was started by start_daemon() or saturnin-daemon script.