Removed deferToThread for ASGI instance constructor (#218)

The previous behaviour was from an older spec.
This commit is contained in:
Anders Jensen 2018-07-22 18:54:42 +02:00 committed by Andrew Godwin
parent e16b58bcb5
commit adb622d4f5
3 changed files with 4 additions and 6 deletions

View File

@ -3,7 +3,7 @@ import time
import traceback import traceback
from urllib.parse import unquote from urllib.parse import unquote
from twisted.internet.defer import inlineCallbacks from twisted.internet.defer import inlineCallbacks, maybeDeferred
from twisted.internet.interfaces import IProtocolNegotiationFactory from twisted.internet.interfaces import IProtocolNegotiationFactory
from twisted.protocols.policies import ProtocolWrapper from twisted.protocols.policies import ProtocolWrapper
from twisted.web import http from twisted.web import http
@ -146,7 +146,7 @@ class WebRequest(http.Request):
logger.debug("HTTP %s request for %s", self.method, self.client_addr) logger.debug("HTTP %s request for %s", self.method, self.client_addr)
self.content.seek(0, 0) self.content.seek(0, 0)
# Work out the application scope and create application # Work out the application scope and create application
self.application_queue = yield self.server.create_application(self, { self.application_queue = yield maybeDeferred(self.server.create_application, self, {
"type": "http", "type": "http",
# TODO: Correctly say if it's 1.1 or 1.0 # TODO: Correctly say if it's 1.1 or 1.0
"http_version": self.clientproto.split(b"/")[-1].decode("ascii"), "http_version": self.clientproto.split(b"/")[-1].decode("ascii"),

View File

@ -24,7 +24,6 @@ from concurrent.futures import CancelledError
from twisted.internet import defer, reactor from twisted.internet import defer, reactor
from twisted.internet.endpoints import serverFromString from twisted.internet.endpoints import serverFromString
from twisted.internet.threads import deferToThread
from twisted.logger import STDLibLogObserver, globalLogBeginner from twisted.logger import STDLibLogObserver, globalLogBeginner
from twisted.web import http from twisted.web import http
@ -171,7 +170,6 @@ class Server(object):
### Internal event/message handling ### Internal event/message handling
@defer.inlineCallbacks
def create_application(self, protocol, scope): def create_application(self, protocol, scope):
""" """
Creates a new application instance that fronts a Protocol instance Creates a new application instance that fronts a Protocol instance
@ -183,7 +181,7 @@ class Server(object):
assert "application_instance" not in self.connections[protocol] assert "application_instance" not in self.connections[protocol]
# Make an instance of the application # Make an instance of the application
input_queue = asyncio.Queue() input_queue = asyncio.Queue()
application_instance = yield deferToThread(self.application, scope=scope) application_instance = self.application(scope=scope)
# 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:
return None return None

View File

@ -66,7 +66,7 @@ class WebSocketProtocol(WebSocketServerProtocol):
] ]
# Make new application instance with scope # Make new application instance with scope
self.path = request.path.encode("ascii") self.path = request.path.encode("ascii")
self.application_deferred = self.server.create_application(self, { self.application_deferred = defer.maybeDeferred(self.server.create_application, self, {
"type": "websocket", "type": "websocket",
"path": unquote(self.path.decode("ascii")), "path": unquote(self.path.decode("ascii")),
"headers": self.clean_headers, "headers": self.clean_headers,