Re:You might want async in your project
by maxbond on Saturday September 09, 2023 @04:39PM
(#37450045)
NB: the function in Python >= 3.9 is to_thread()
https://docs.python.org/3/library/asyncio-task.html#asyncio....
Re:You might want async in your project
by pdhborges on Saturday September 09, 2023 @06:11PM
(#37450788)
They are not polyfills. Multiple scheduling modes are provided for libraries that are not thread safe (it's a total mess and I avoid these wrappers like the plague)
Re:You might want async in your project
by maxbond on Saturday September 09, 2023 @09:10PM
(#37451953)
I've had to weld some async and sync Python together with queues and callbacks, it's not pretty.
Re:You might want async in your project
by mplanchard on Saturday September 09, 2023 @04:13PM
(#37449815)
“run in a threadpool” isn’t the same as creating a thread though
> 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
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
Ofc this is a python example. I have no idea how it works in different languages.