socketify.py
socketify.py copied to clipboard
Not able to run Litestar app with lifespan
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)]
seems like it has to do with TaskGroup creation is there anything we can provide to help on this ?
Fixed in the main branch