emmett-framework / granian

A Rust HTTP server for Python applications
BSD 3-Clause "New" or "Revised" License
2.86k stars 83 forks source link

sniffio._impl.AsyncLibraryNotFoundError: unknown async library, or not in async context #127

Closed sfahad1414 closed 1 year ago

sfahad1414 commented 1 year ago

[ERROR] Exception in callback <built-in method _loop_task of builtins.CallbackRunnerHTTP object at 0x7f715067de70>

handle: Traceback (most recent call last): File "uvloop/cbhandles.pyx", line 61, in uvloop.loop.Handle._run File "/app/kairon/chat/server.py", line 258, in main await app.call(scope=scope, receive=receive, send=send) File "/usr/local/lib/python3.10/site-packages/fastapi/applications.py", line 292, in call await super().call(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/starlette/applications.py", line 122, in call await self.middleware_stack(scope, receive, send) File "/usr/local/lib/python3.10/site-packages/elasticapm/instrumentation/packages/asyncio/starlette.py", line 48, in call return await wrapped(*args, **kwargs) File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in call raise exc File "/usr/local/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in call await self.app(scope, receive, _send) File "/usr/local/lib/python3.10/site-packages/starlette/middleware/base.py", line 29, in call response_sent = anyio.Event() File "/usr/local/lib/python3.10/site-packages/anyio/_core/_synchronization.py", line 79, in new return get_asynclib().Event() File "/usr/local/lib/python3.10/site-packages/anyio/_core/_eventloop.py", line 147, in get_asynclib asynclib_name = sniffio.current_async_library() File "/usr/local/lib/python3.10/site-packages/sniffio/_impl.py", line 93, in current_async_library raise AsyncLibraryNotFoundError( sniffio._impl.AsyncLibraryNotFoundError: unknown async library, or not in async context

gi0baro commented 1 year ago

Looks like you launched Granian with --opt. As described in the readme, some implementations are not compatible with the optimizations, so just keep those optimizations off (as per default).