You've already forked RekomenciBackend
feat(): format & proper startup (make main async for uvicorn to inherit current asyncio event loop)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import argparse
|
||||
import asyncio
|
||||
import os
|
||||
import selectors
|
||||
import sys
|
||||
from collections.abc import AsyncIterator
|
||||
from contextlib import asynccontextmanager
|
||||
@@ -70,27 +71,27 @@ def make_asgi_application(
|
||||
return app
|
||||
|
||||
|
||||
def _main(
|
||||
async def _main(
|
||||
configuration_path: Path,
|
||||
) -> None:
|
||||
configuration = load_configuration(configuration_path)
|
||||
ioc = make_ioc(configuration)
|
||||
asgi_application = make_asgi_application(ioc)
|
||||
|
||||
uvicorn.run(
|
||||
asgi_application,
|
||||
port=configuration.server.port,
|
||||
config = uvicorn.Config(
|
||||
app=asgi_application,
|
||||
host=configuration.server.host,
|
||||
port=configuration.server.port,
|
||||
log_config=LOG_CONFIG,
|
||||
access_log=configuration.server.access_log,
|
||||
)
|
||||
server = uvicorn.Server(config)
|
||||
await server.serve()
|
||||
|
||||
|
||||
def main() -> None:
|
||||
if sys.platform == "win32":
|
||||
from asyncio import WindowsSelectorEventLoopPolicy # noqa: PLC0415
|
||||
|
||||
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
|
||||
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
||||
|
||||
arg_parser = argparse.ArgumentParser()
|
||||
arg_parser.add_argument("configuration", default=None)
|
||||
@@ -103,7 +104,7 @@ def main() -> None:
|
||||
"pass the path to the config or specify it in the environment variables `CONFIGURATION_PATH`",
|
||||
)
|
||||
|
||||
_main(Path(configuration_path))
|
||||
asyncio.run(_main(Path(configuration_path)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import asyncio
|
||||
|
||||
from dishka import FromDishka
|
||||
from dishka.integrations.fastapi import DishkaRoute
|
||||
from fastapi import APIRouter
|
||||
|
||||
Reference in New Issue
Block a user