From 4d4ac45b18fba57d0c445e8e357ade32be48ce4d Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Tue, 6 Apr 2021 17:21:46 +0100 Subject: [PATCH] Use partial() to wrap Server.handle_reply() Fixes #332. --- CHANGELOG.txt | 4 ++++ daphne/server.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 4e0b0a9..0584eb9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,7 @@ +* Fixed a bug where ``send`` passed to applications wasn't a true async + function but a lambda wrapper, preventing it from being used with + ``asgiref.sync.async_to_sync()``. + 3.0.1 (2020-11-12) ------------------ diff --git a/daphne/server.py b/daphne/server.py index 77bd2d1..fd1daf1 100755 --- a/daphne/server.py +++ b/daphne/server.py @@ -22,6 +22,7 @@ else: import logging import time from concurrent.futures import CancelledError +from functools import partial from twisted.internet import defer, reactor from twisted.internet.endpoints import serverFromString @@ -203,7 +204,7 @@ class Server(object): application_instance = self.application( scope=scope, receive=input_queue.get, - send=lambda message: self.handle_reply(protocol, message), + send=partial(self.handle_reply, protocol), ) # Run it, and stash the future for later checking if protocol not in self.connections: