2
0

hypercorn forks workers now, don't want that - manual hypercorn calls

This commit is contained in:
Stefan Bühler 2023-01-12 15:13:27 +01:00
parent 26357f7f21
commit 867044a407
4 changed files with 38 additions and 13 deletions

View File

@ -35,3 +35,4 @@ where = src
console_scripts = console_scripts =
capport-control = capport.control.run:main capport-control = capport.control.run:main
capport-stats = capport.stats:main capport-stats = capport.stats:main
capport-webui = capport.api.hypercorn_run:main

View File

@ -1,12 +0,0 @@
from __future__ import annotations
import capport.config
_config = capport.config.Config.load_default_once()
worker_class = 'trio'
if _config.server_names:
server_names = _config.server_names
elif not _config.debug:
raise Exception("production setup requires server-names in config (list of accepted hostnames in http requests)")

View File

@ -0,0 +1,36 @@
from __future__ import annotations
import hypercorn.config
import hypercorn.trio.run
import hypercorn.utils
import capport.config
def run(config: hypercorn.config.Config) -> None:
sockets = config.create_sockets()
assert config.worker_class == 'trio'
hypercorn.trio.run.trio_worker(config=config, sockets=sockets)
for sock in sockets.secure_sockets:
sock.close()
for sock in sockets.insecure_sockets:
sock.close()
def main() -> None:
_config = capport.config.Config.load_default_once()
hypercorn_config = hypercorn.config.Config()
hypercorn_config.application_path = 'capport.api.app'
hypercorn_config.worker_class = 'trio'
if _config.server_names:
hypercorn_config.server_names = _config.server_names
elif not _config.debug:
raise Exception(
"production setup requires server-names in config (list of accepted hostnames in http requests)"
)
run(hypercorn_config)

View File

@ -5,4 +5,4 @@ set -e
base=$(dirname "$(readlink -f "$0")") base=$(dirname "$(readlink -f "$0")")
cd "${base}" cd "${base}"
exec ./venv/bin/hypercorn --config python:capport.api.hypercorn_conf capport.api.app "$@" exec ./venv/bin/capport-webui "$@"