3 ms·
FastAPI docs, case when you don't create an async route > When you declare a path operation function with normal def instead of async def, it is run in an exte
by tomwojcik 3y ago
FastAPI docs, case when you don't create an async route
> When you declare a path operation function with normal def instead of async def, it is run in an external threadpool that is then awaited, instead of being called directly (as it would block the server).
https://fastapi.tiangolo.com/async/#path-operation-functions https://fastapi.tiangolo.com/async/#path-operation-functions
OP either meant this, or its variation, such as async_to_sync and sync_to_async.
https://github.com/django/asgiref/blob/main/asgiref/sync.py https://github.com/django/asgiref/blob/main/asgiref/sync.py
Ofc this is a python example. I have no idea how it works in different languages.
- deleted 3y ago[deleted]
- mplanchard 3y ago“run in a threadpool” isn’t the same as creating a thread though
- maxbond 3y agoNB: In Python >= 3.9 the idiomatic way to do this is to_thread(), not familiar with these ASGI functions but I would guess they're a polyfill and/or predate 3.9. https://docs.python.org/3/library/asyncio-task.html#asyncio.to_thread https://docs.python.org/3/library/asyncio-task.html#asyncio....