Skip to content

Daemon mode switch #283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/hypercorn/__main__.py
Original file line number Diff line number Diff line change
@@ -215,6 +215,19 @@ def _convert_verify_mode(value: str) -> ssl.VerifyMode:
default=sentinel,
type=int,
)
daemon_group = parser.add_mutually_exclusive_group()
daemon_group.add_argument(
"--daemon",
action="store_true",
help="Spawn workers in daemon mode"
)
daemon_group.add_argument(
"--no-daemon",
action="store_false",
dest="daemon",
help="Spawn workers in normal mode (without daemon)"
)
parser.set_defaults(daemon=True)
args = parser.parse_args(sys_args or sys.argv[1:])
config = _load_config(args.config)
config.application_path = args.application
@@ -301,6 +314,8 @@ def _convert_verify_mode(value: str) -> ssl.VerifyMode:
if len(args.server_names) > 0:
config.server_names = args.server_names

config.daemon = args.daemon

return run(config)


9 changes: 9 additions & 0 deletions src/hypercorn/config.py
Original file line number Diff line number Diff line change
@@ -60,6 +60,7 @@ class Config:
_quic_addresses: List[Tuple] = []
_log: Optional[Logger] = None
_root_path: str = ""
_daemon: bool = True

access_log_format = '%(h)s %(l)s %(l)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
accesslog: Union[logging.Logger, str, None] = None
@@ -118,6 +119,14 @@ def set_cert_reqs(self, value: int) -> None:

cert_reqs = property(None, set_cert_reqs)

@property
def daemon(self) -> bool:
return self._daemon

@daemon.setter
def daemon(self, value: bool) -> None:
self._daemon = value

@property
def log(self) -> Logger:
if self._log is None:
2 changes: 1 addition & 1 deletion src/hypercorn/run.py
Original file line number Diff line number Diff line change
@@ -121,7 +121,7 @@ def _populate(
target=worker_func,
kwargs={"config": config, "shutdown_event": shutdown_event, "sockets": sockets},
)
process.daemon = True
process.daemon = config.daemon
try:
process.start()
except PicklingError as error: