Skip to content

Commit fbcc9c3

Browse files
committed
Add a config and command line argument to daemonise the workers
This is often something users wish to control as some environments don't support daemon processes.
1 parent ed6cd40 commit fbcc9c3

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/hypercorn/__main__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def main(sys_args: list[str] | None = None) -> int:
6161
help="Location of a TOML config file, or when prefixed with `file:` a Python file, or when prefixed with `python:` a Python module.", # noqa: E501
6262
default=None,
6363
)
64+
parser.add_argument(
65+
"-D",
66+
"--daemon",
67+
help="Run the workers as daemons",
68+
action="store_true",
69+
default=sentinel,
70+
)
6471
parser.add_argument(
6572
"--debug",
6673
help="Enable debug mode, i.e. extra logging and checks",
@@ -240,6 +247,8 @@ def _convert_verify_mode(value: str) -> ssl.VerifyMode:
240247
config.cert_reqs = args.cert_reqs
241248
if args.ciphers is not sentinel:
242249
config.ciphers = args.ciphers
250+
if args.daemon is not sentinel:
251+
config.daemon = args.daemon
243252
if args.debug is not sentinel:
244253
config.debug = args.debug
245254
if args.error_log is not sentinel:

src/hypercorn/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class Config:
7171
ca_certs: str | None = None
7272
certfile: str | None = None
7373
ciphers: str = "ECDHE+AESGCM"
74+
daemon = True
7475
debug = False
7576
dogstatsd_tags = ""
7677
errorlog: logging.Logger | str | None = "-"

src/hypercorn/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def _populate(
121121
target=worker_func,
122122
kwargs={"config": config, "shutdown_event": shutdown_event, "sockets": sockets},
123123
)
124-
process.daemon = True
124+
process.daemon = config.daemon
125125
try:
126126
process.start()
127127
except PicklingError as error:

0 commit comments

Comments
 (0)