Opened 84 minutes ago
#36863 new Bug
Under WSGI, multiple calls to asgiref.sync.async_to_sync within the same request do not share the same event loop.
| Reported by: | Mykhailo Havelia | Owned by: | |
|---|---|---|---|
| Component: | HTTP handling | Version: | 6.0 |
| Severity: | Normal | Keywords: | async, wsgi |
| Cc: | Mykhailo Havelia | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Each call creates a new thread with its own event loop. This commonly happens in middlewares and signals, causing a single request to spawn multiple threads and event loops, which is unnecessary and prevents reuse of async resources.
This could be addressed by introducing a per-request async context, for example as shown in this draft implementation:
https://github.com/Arfey/django/pull/5/changes
Note:
See TracTickets
for help on using tickets.