mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-09 12:57:46 +00:00
support newer python versions (#11675)
When we added the option of getting `al2023` in addition to `al2`, this required a python version bump for those apps on `al2023`. Python 3.10 had a breaking minor change. https://github.com/vercel/vercel/pull/11541 mostly fixed it, with some comments. OP hasn't replied to feedback on that PR, so I've take it over from them.
This commit is contained in:
5
.changeset/angry-moles-cross.md
Normal file
5
.changeset/angry-moles-cross.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@vercel/python": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
support newer python versions
|
||||||
@@ -13,6 +13,7 @@ sys.modules["__VC_HANDLER_MODULE_NAME"] = __vc_module
|
|||||||
__vc_spec.loader.exec_module(__vc_module)
|
__vc_spec.loader.exec_module(__vc_module)
|
||||||
__vc_variables = dir(__vc_module)
|
__vc_variables = dir(__vc_module)
|
||||||
|
|
||||||
|
_use_legacy_asyncio = sys.version_info < (3, 10)
|
||||||
|
|
||||||
def format_headers(headers, decode=False):
|
def format_headers(headers, decode=False):
|
||||||
keyToList = {}
|
keyToList = {}
|
||||||
@@ -198,16 +199,25 @@ elif 'app' in __vc_variables:
|
|||||||
ASGI instance using the connection scope.
|
ASGI instance using the connection scope.
|
||||||
Runs until the response is completely read from the application.
|
Runs until the response is completely read from the application.
|
||||||
"""
|
"""
|
||||||
|
if _use_legacy_asyncio:
|
||||||
loop = asyncio.new_event_loop()
|
loop = asyncio.new_event_loop()
|
||||||
self.app_queue = asyncio.Queue(loop=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})
|
self.put_message({'type': 'http.request', 'body': body, 'more_body': False})
|
||||||
|
|
||||||
asgi_instance = app(self.scope, self.receive, self.send)
|
asgi_instance = app(self.scope, self.receive, self.send)
|
||||||
|
|
||||||
|
if _use_legacy_asyncio:
|
||||||
asgi_task = loop.create_task(asgi_instance)
|
asgi_task = loop.create_task(asgi_instance)
|
||||||
loop.run_until_complete(asgi_task)
|
loop.run_until_complete(asgi_task)
|
||||||
|
else:
|
||||||
|
asyncio.run(self.run_asgi_instance(asgi_instance))
|
||||||
return self.response
|
return self.response
|
||||||
|
|
||||||
|
async def run_asgi_instance(self, asgi_instance):
|
||||||
|
await asgi_instance
|
||||||
|
|
||||||
def put_message(self, message):
|
def put_message(self, message):
|
||||||
self.app_queue.put_nowait(message)
|
self.app_queue.put_nowait(message)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user