Skip to content
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

Not able to run Litestar app with lifespan #135

Open
euri10 opened this issue Aug 24, 2023 · 1 comment
Open

Not able to run Litestar app with lifespan #135

euri10 opened this issue Aug 24, 2023 · 1 comment

Comments

@euri10
Copy link

euri10 commented Aug 24, 2023

Describe the bug
lifespan crashes without any interesting info

To Reproduce
Steps to reproduce the behavior:

run that simple app, it runs ok with lifespan=False and crashes with lifespan=True
ERROR - 2023-08-24 16:04:36,385 - root - asgi - Uncaught Exception: unknown async library, or not in async context

from contextlib import asynccontextmanager
from functools import partial
from typing import AsyncGenerator

from litestar import Litestar, get, Request
from socketify import ASGI


@asynccontextmanager
async def lifespan(_app: Litestar) -> AsyncGenerator[None, None]:
    print(1)
    yield
    print(2)


def get_app() -> Litestar:
    @get("/")
    async def index(request: Request) -> int:
        return 1

    app = Litestar(route_handlers=[index],
                   lifespan=[partial(lifespan)]
                   )

    return app


if __name__ == "__main__":
    app = get_app()
    ASGI(app, lifespan=True).listen(8000).run(1)

Expected behavior
well it should not crash

Desktop (please complete the following information):

  • OS: [debian11]
  • Browser [chrome]
  • Version [Version 116.0.5845.96 (Official Build) (64-bit)]
@euri10
Copy link
Author

euri10 commented Jan 2, 2024

seems like it has to do with TaskGroup creation
is there anything we can provide to help on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant