With Django 4.0 being 3.8+ the required `contextvars` module is available.
Adjust `ASGIHandler` to use `ThreadSensitiveContext`
[https://github.com/django/django/pull/13882 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/32889>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32889#comment:1>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"36fa071d6ebd18a61c4d7f1b5c9d17106134bd44" 36fa071]:
{{{
#!CommitTicketReference repository=""
revision="36fa071d6ebd18a61c4d7f1b5c9d17106134bd44"
Fixed #32889 -- Allowed per-request sync_to_async context in ASGIHandler .
By using a asgiref's ThreadSensitiveContext context manager, requests
will be able to execute independently of other requests when sync work
is involved.
Prior to this commit, a single global thread was used to execute any
sync work independent of the request from which that work was scheduled.
This could result in contention for the global sync thread in the case
of a slow sync function.
Requests are now isolated to their own sync thread.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32889#comment:2>