Open medihack opened 1 month ago
I took a quick look at replacing asgiref.sync_to_async
with asyncio.to_thread
, but I don't think it is worth it. We use sync_to_async
quite often as a decorator, which is not directly possible with asyncio.to_thread
. And asgiref
also has the convenient method the other way around (async_to_sync
).
I think it is more nuanced than that.
asgiref
might need to stay for the Django integration as per their async doc.
However, there is no need to make it a dependency for any consumer that is not using Django.
We use
sync_to_async
quite often as a decorator, which is not directly possible with asyncio.to_thread
That should be fine. Beside Django integration, it seems it is only used in tests. That could stay there or it would be trivial to update to not use a decorator and explicitly wrap the function.
Ok, good point. I will give it a try.
So shall I close this as #1224 was merged or do we keep it open for the replacement of sync_to_async ?
So shall I close this as #1224 was merged or do we keep it open for the replacement of sync_to_async ?
PR #1226 will close it :-)
As discussed on Discord, we want to drop support for Python v3.8 as it reached its end-of-life. We then can use
asyncio.to_thread
(available in Python >= 3.9) instead ofasgiref.sync.sync_to_async
(we should then do this together in the 3.0 release).