Skip to content

Commit f91aad3

Browse files
tonybaloneyYunchuWanggavin-aguiar
authored
No temporary loop for ASGI middleware (#148)
* Yield a disconnect on the second receive call * Use asyncio.run to handle existing/new event loop for Python 3.7+ --------- Co-authored-by: peterstone2017 <12449837+YunchuWang@users.noreply.github.com> Co-authored-by: gavin-aguiar <80794152+gavin-aguiar@users.noreply.github.com>
1 parent ef781d3 commit f91aad3

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

azure/functions/_http_asgi.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ def __init__(self, app):
150150
self._usage_reported = True
151151

152152
self._app = app
153-
self._loop = asyncio.new_event_loop()
154153
self.main = self._handle
155154

156155
def handle(self, req: HttpRequest, context: Optional[Context] = None):
@@ -172,9 +171,8 @@ async def main(req, context):
172171

173172
def _handle(self, req, context):
174173
asgi_request = AsgiRequest(req, context)
175-
asyncio.set_event_loop(self._loop)
176174
scope = asgi_request.to_asgi_http_scope()
177-
asgi_response = self._loop.run_until_complete(
175+
asgi_response = asyncio.run(
178176
AsgiResponse.from_app(self._app, scope, req.get_body())
179177
)
180178

0 commit comments

Comments
 (0)