You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
asgiref version 3.3.0 changed the default value of the thread_sensitive parameter to True. This is a safer default, and in many cases interacting with Django the correct value, but be sure to evaluate uses of sync_to_async() if updating asgiref from a prior version.
Thread-sensitive mode is quite special, and does a lot of work to run all functions in the same thread. Note, though, that it relies on usage of async_to_sync() above it in the stack to correctly run things on the main thread. If you use asyncio.run() or similar, it will fall back to running thread-sensitive functions in a single, shared thread, but this will not be the main thread.
The reason this is needed in Django is that many libraries, specifically database adapters, require that they are accessed in the same thread that they were created in. Also a lot of existing Django code assumes it all runs in the same thread, e.g.
Since now the minimum suppoted django version is 4.2 which requires asgiref >= 3.6.0 and has many async ORM methods I have two questions:
Is still woth having this specific override of async_to_sync?
Should we update the docs to reflect the changes in django to provide better usage suggestions?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
From django docs:
https://docs.djangoproject.com/en/stable/topics/async/#sync-to-async
Since now the minimum suppoted django version is 4.2 which requires asgiref >= 3.6.0 and has many async ORM methods I have two questions:
async_to_sync
?Beta Was this translation helpful? Give feedback.
All reactions