#32172: Adapt signals to allow async handlers -------------------------------------+------------------------------------- Reporter: Carlton Gibson | Owner: | Konstantin Volkov Type: New feature | Status: assigned Component: Core (Other) | Version: master Severity: Normal | Resolution: Keywords: async | Triage Stage: Accepted Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+------------------------------------- Description changed by Carlton Gibson:
Old description: > Currently (circa 3.1) we have a couple of `sync_to_async()` usages in > [https://github.com/django/django/blob/009fddc96b88a9aee1232d6a2637f2970fdcfb50/django/core/handlers/asgi.py#L154 > the main line of `ASGIHandler.__call__()`], for the request life cycle > signals: > > {{{ > await sync_to_async(signals.request_started.send, > thread_sensitive=True)(sender=self.__class__, scope=scope) > }}} > > Much as is done of the middleware, > [https://github.com/django/django/blob/76181308fb02e67794d0cc1471766a5d7e4c877e/django/core/handlers/base.py#L26 > adapting to accept either synchronous or asynchronous middleware > classes], it would be good to be able to push that `sync_to_async()` call > down into the `send()` method, allowing signal handlers to be either sync > (as now) or async coroutines. > > This would give us the option of having a completely async request > pathway, if we were to remove all synchronous middleware and signal > handlers. > > There will need to be some discussion, perhaps on a PR, or the > [https://forum.djangoproject.com/c/internals/async/8 Forum's Async > category] but opening this ticket to track efforts. New description: Currently (circa 3.1) we have a couple of `sync_to_async()` usages in [https://github.com/django/django/blob/009fddc96b88a9aee1232d6a2637f2970fdcfb50/django/core/handlers/asgi.py#L154 the main line of `ASGIHandler.__call__()`], for the request life cycle signals: {{{ await sync_to_async(signals.request_started.send, thread_sensitive=True)(sender=self.__class__, scope=scope) }}} Much as is done of the middleware, [https://github.com/django/django/blob/76181308fb02e67794d0cc1471766a5d7e4c877e/django/core/handlers/base.py#L26 adapting to accept either synchronous or asynchronous middleware classes], it would be good to be able to push that `sync_to_async()` call down into the `send()` method, allowing signal handlers to be either sync (as now) or async coroutines. This would give us the option of having a completely async request pathway, if we were to remove all synchronous middleware and signal handlers. There will need to be some discussion of exact implementation, perhaps on a PR, or the [https://forum.djangoproject.com/c/internals/async/8 Forum's Async category] but opening this ticket to track efforts. -- -- Ticket URL: <https://code.djangoproject.com/ticket/32172#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/071.3baef27df58ec55e135f63b76cbf84f5%40djangoproject.com.