From 2d74d1ad94fa3ae48651778a89918524c7910dfb Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 30 Oct 2022 22:07:44 +0800 Subject: [PATCH] Fix tests for Python 3.11 --- gns3server/utils/asyncio/pool.py | 2 +- gns3server/web/route.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/gns3server/utils/asyncio/pool.py b/gns3server/utils/asyncio/pool.py index 0015e29c..8a900722 100644 --- a/gns3server/utils/asyncio/pool.py +++ b/gns3server/utils/asyncio/pool.py @@ -39,7 +39,7 @@ class Pool(): while len(self._tasks) > 0 or len(pending) > 0: while len(self._tasks) > 0 and len(pending) < self._concurrency: task, args, kwargs = self._tasks.pop(0) - pending.add(task(*args, **kwargs)) + pending.add(asyncio.create_task(task(*args, **kwargs))) (done, pending) = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED) for task in done: if task.exception(): diff --git a/gns3server/web/route.py b/gns3server/web/route.py index e788a32c..115d209c 100644 --- a/gns3server/web/route.py +++ b/gns3server/web/route.py @@ -164,8 +164,6 @@ class Route(object): "description": kw.get("description", ""), }) - func = asyncio.coroutine(func) - async def control_schema(request): # This block is executed at each method call server_config = Config.instance().get_section_config("Server") @@ -181,7 +179,10 @@ class Route(object): response = Response(request=request, route=route, output_schema=output_schema) request = await parse_request(request, None, raw) - await func(request, response) + if asyncio.iscoroutinefunction(func): + await func(request, response) + else: + func(request, response) return response # API call @@ -195,7 +196,10 @@ class Route(object): except OSError as e: log.warning("Could not write to the record file {}: {}".format(record_file, e)) response = Response(request=request, route=route, output_schema=output_schema) - await func(request, response) + if asyncio.iscoroutinefunction(func): + await func(request, response) + else: + func(request, response) except aiohttp.web.HTTPBadRequest as e: response = Response(request=request, route=route) response.set_status(e.status)