diff options
| author | Carlton Gibson <carlton.gibson@noumenal.es> | 2020-10-22 09:35:06 +0200 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2020-10-27 11:24:07 +0100 |
| commit | e17ee4468875077b90b70bb6a589ebad7493f757 (patch) | |
| tree | 8223fa73e2205607e30cb30034667c2fc1bf1d6e /docs | |
| parent | 0b4fe82c7405ba96f2eb25b954a8f498cc8364b3 (diff) | |
Fixed #32128 -- Added asgiref 3.3 compatibility.
Thread sensitive parameter is True by default from asgiref v3.3.0.
Added an explicit thread_sensitive=False to previously implicit uses.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/3.1.3.txt | 2 | ||||
| -rw-r--r-- | docs/topics/async.txt | 24 |
2 files changed, 18 insertions, 8 deletions
diff --git a/docs/releases/3.1.3.txt b/docs/releases/3.1.3.txt index 6f526aa5c9..300e4aff54 100644 --- a/docs/releases/3.1.3.txt +++ b/docs/releases/3.1.3.txt @@ -51,3 +51,5 @@ Bugfixes * Fixed a regression in Django 3.1 that invalidated pre-Django 3.1 password reset tokens (:ticket:`32130`). + +* Added support for ``asgiref`` 3.3 (:ticket:`32128`). diff --git a/docs/topics/async.txt b/docs/topics/async.txt index a2f702b8e3..b25dee7605 100644 --- a/docs/topics/async.txt +++ b/docs/topics/async.txt @@ -214,14 +214,14 @@ as ensuring threadlocals work, it also enables the ``thread_sensitive`` mode of ``sync_to_async()`` ------------------- -.. function:: sync_to_async(sync_function, thread_sensitive=False) +.. function:: sync_to_async(sync_function, thread_sensitive=True) Takes a sync function and returns an async function that wraps it. Can be used as either a direct wrapper or a decorator:: from asgiref.sync import sync_to_async - async_function = sync_to_async(sync_function) + async_function = sync_to_async(sync_function, thread_sensitive=False) async_function = sync_to_async(sensitive_sync_function, thread_sensitive=True) @sync_to_async @@ -234,13 +234,21 @@ directions. Sync functions tend to be written assuming they all run in the main thread, so :func:`sync_to_async` has two threading modes: -* ``thread_sensitive=False`` (the default): the sync function will run in a - brand new thread which is then closed once the invocation completes. +* ``thread_sensitive=True`` (the default): the sync function will run in the + same thread as all other ``thread_sensitive`` functions. This will be the + main thread, if the main thread is synchronous and you are using the + :func:`async_to_sync` wrapper. -* ``thread_sensitive=True``: the sync function will run in the same thread as - all other ``thread_sensitive`` functions. This will be the main thread, if - the main thread is synchronous and you are using the :func:`async_to_sync` - wrapper. +* ``thread_sensitive=False``: the sync function will run in a brand new thread + which is then closed once the invocation completes. + +.. warning:: + + ``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* |
