From 46963ba4644d7abc8dc653c99bc76222af526964 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sun, 6 Jun 2021 20:05:12 +0100 Subject: [PATCH] Work around a bug in uasyncio's create_server() function --- src/microdot_asyncio.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/microdot_asyncio.py b/src/microdot_asyncio.py index 0fad5db..3050009 100644 --- a/src/microdot_asyncio.py +++ b/src/microdot_asyncio.py @@ -162,7 +162,14 @@ async def aclose(self): host=host, port=port)) self.server = await asyncio.start_server(serve, host, port) - await self.server.wait_closed() + while True: + try: + await self.server.wait_closed() + break + except AttributeError: # pragma: no cover + # the task hasn't been initialized in the server object yet + # wait a bit and try again + await asyncio.sleep(0.1) def run(self, host='0.0.0.0', port=5000, debug=False): """Start the web server. This function does not normally return, as