-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bugfix: ASGI support for newer python versions > 3.9 #11541
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -191,23 +191,33 @@ def __init__(self, scope): | |||||
self.state = ASGICycleState.REQUEST | ||||||
self.app_queue = None | ||||||
self.response = {} | ||||||
self._legacy_asyncio = sys.version_info < (3, 10) | ||||||
|
||||||
def __call__(self, app, body): | ||||||
""" | ||||||
Receives the application and any body included in the request, then builds the | ||||||
ASGI instance using the connection scope. | ||||||
Runs until the response is completely read from the application. | ||||||
""" | ||||||
loop = asyncio.new_event_loop() | ||||||
self.app_queue = asyncio.Queue(loop=loop) | ||||||
if self._legacy_asyncio: | ||||||
loop = asyncio.new_event_loop() | ||||||
self.app_queue = asyncio.Queue(loop=loop) | ||||||
else: | ||||||
self.app_queue = asyncio.Queue() | ||||||
self.put_message({'type': 'http.request', 'body': body, 'more_body': False}) | ||||||
|
||||||
asgi_instance = app(self.scope, self.receive, self.send) | ||||||
|
||||||
asgi_task = loop.create_task(asgi_instance) | ||||||
loop.run_until_complete(asgi_task) | ||||||
if self._legacy_asyncio: | ||||||
asgi_task = loop.create_task(asgi_instance) | ||||||
loop.run_until_complete(asgi_task) | ||||||
else: | ||||||
asyncio.run(self.run_asgi_instance(asgi_instance)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually need a separate function? From what I see in the handler, at this point in time, we already know that
Suggested change
|
||||||
return self.response | ||||||
|
||||||
async def run_asgi(self, asgi_instance): | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like this should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @winglian - just checking to see if you saw this? |
||||||
await asgi_instance | ||||||
|
||||||
def put_message(self, message): | ||||||
self.app_queue.put_nowait(message) | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of creating a class member variable just for checking. How about we declare a local variable at the top of the
__call__
function instead?