cofin / litestar-granian

Granian plugin for Litestar
MIT License
16 stars 3 forks source link

Litestar CLI cause crash on application exit #21

Open Forceres opened 3 months ago

Forceres commented 3 months ago

Litestar CLI cause crash on application exit, but when I start via granian cli, it works cool. MCVE:

   def init_app(
    init_api_routers: Callable or None,
    structlog_config: StructLoggingConfig,
    context: str,
    middlewares: list[Middleware],
) -> Litestar:
    set_event_loop_policy(EventLoopPolicy())

    if init_api_routers is None:

        def init_api_routers():
            return []

    structlog_plugin = StructlogPlugin(StructlogConfig(structlog_logging_config=structlog_config))
    app = Litestar(
        route_handlers=[*init_api_routers()],
        middleware=middlewares,
        plugins=[structlog_plugin, GranianPlugin()],
    )
    return app

   def init_apps() -> Litestar:
    context = "schedule_service"
    structlog_config = init_logging(context)
    logger = get_logger()
    app: Litestar = init_app(
        None, structlog_config, context, [GZipMiddleware]
    )
    app.on_startup = []
    app.on_shutdown = []
    app.logger = logger
    return app

app = init_apps()
cofin commented 3 months ago

Can you provide the traceback that you receive here? Also any info on OS and python version would be helpful.

Forceres commented 2 months ago

No traceback, just one message Screenshot_20240720_223533 I use python 3.11.5, and Linux Fedora 40 KDE Plasma

Forceres commented 2 months ago

Can you provide the traceback that you receive here? Also any info on OS and python version would be helpful.

Last update fixed the problem with crash and not process exiting, but now here is a new problem with logs, some logs are output after application close in command line like here: image