3
0

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

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

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)