procrastinate icon indicating copy to clipboard operation
procrastinate copied to clipboard

Remove asgiref from non Django code

Open medihack opened this issue 1 year ago • 6 comments

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 of asgiref.sync.sync_to_async (we should then do this together in the 3.0 release).

medihack avatar Oct 13 '24 22:10 medihack

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).

medihack avatar Oct 15 '24 21:10 medihack

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.

onlyann avatar Oct 16 '24 06:10 onlyann

Ok, good point. I will give it a try.

medihack avatar Oct 16 '24 14:10 medihack

So shall I close this as #1224 was merged or do we keep it open for the replacement of sync_to_async ?

ewjoachim avatar Oct 19 '24 11:10 ewjoachim

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 :-)

medihack avatar Oct 19 '24 12:10 medihack

https://github.com/procrastinate-org/procrastinate/pull/1244 removed py3.8 from the codebase. This issue now only is about asgiref.

ewjoachim avatar Dec 30 '24 15:12 ewjoachim