Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

thegamecracks/daemon-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

daemon-example

A simple demonstration of managing daemon processes.

Usage

With Python 3.11+, install the package with:

python -m venv
source .venv/bin/activate  # .venv\Scripts\activate on Windows
pip install git+https://github.com/thegamecracks/daemon-example@v1.3.0

Then play around with the CLI:

$ thedaemon  # or python -m thedaemon
usage: thedaemon [-h] [-P PORT] {start,ping,stop} ...

positional arguments:
  {start,ping,stop}
    start               Start the daemon process.
    ping                Check if the daemon process is running.
    stop                Stop the daemon process.

options:
  -h, --help            show this help message and exit
  -P PORT, --port PORT  The daemon port to use. (default: 21365)

$ thedaemon start

$ thedaemon start
Daemon already running

$ thedaemon ping
pong

$ thedaemon stop
stop

$ thedaemon ping
Failed to connect to daemon; did you start it?

thedaemon start can be passed a --no-daemon flag if you simply want to run the server in the foreground. Beware that on Windows, the server will be unable to handle signals like SIGINT (keyboard interrupt).

The daemon port can be customized by either passing -P / --port between thedaemon and the subcommand you want to run, or by setting the environment variable THEDAEMON_PORT.

Implementation

thedaemon start starts a socket server to serve as the workload for the background process. It can be communicated with by using thedaemon ping. thedaemon stop will connect to the server and send a stop command.

On Unix, a double-fork is performed to daemonize the server.

On Windows, a detached process is created using pythonw.exe as the executable.

References

License

This project is written under the MIT license.

About

A simple demonstration of managing daemon processes.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages