Use partial() to wrap Server.handle_reply()

Fixes #332.
This commit is contained in:
Adam Johnson 2021-04-06 17:21:46 +01:00
parent aac4708a61
commit 4d4ac45b18
2 changed files with 6 additions and 1 deletions

View File

@ -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) 3.0.1 (2020-11-12)
------------------ ------------------

View File

@ -22,6 +22,7 @@ else:
import logging import logging
import time import time
from concurrent.futures import CancelledError from concurrent.futures import CancelledError
from functools import partial
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
from twisted.internet.endpoints import serverFromString from twisted.internet.endpoints import serverFromString
@ -203,7 +204,7 @@ class Server(object):
application_instance = self.application( application_instance = self.application(
scope=scope, scope=scope,
receive=input_queue.get, 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 # Run it, and stash the future for later checking
if protocol not in self.connections: if protocol not in self.connections: