1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Fix tests for Python 3.11

This commit is contained in:
grossmj 2022-10-30 22:07:44 +08:00
parent ec50cc7c0d
commit 2d74d1ad94
2 changed files with 9 additions and 5 deletions

View File

@ -39,7 +39,7 @@ class Pool():
while len(self._tasks) > 0 or len(pending) > 0: while len(self._tasks) > 0 or len(pending) > 0:
while len(self._tasks) > 0 and len(pending) < self._concurrency: while len(self._tasks) > 0 and len(pending) < self._concurrency:
task, args, kwargs = self._tasks.pop(0) 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) (done, pending) = await asyncio.wait(pending, return_when=asyncio.FIRST_COMPLETED)
for task in done: for task in done:
if task.exception(): if task.exception():

View File

@ -164,8 +164,6 @@ class Route(object):
"description": kw.get("description", ""), "description": kw.get("description", ""),
}) })
func = asyncio.coroutine(func)
async def control_schema(request): async def control_schema(request):
# This block is executed at each method call # This block is executed at each method call
server_config = Config.instance().get_section_config("Server") 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) response = Response(request=request, route=route, output_schema=output_schema)
request = await parse_request(request, None, raw) request = await parse_request(request, None, raw)
if asyncio.iscoroutinefunction(func):
await func(request, response) await func(request, response)
else:
func(request, response)
return response return response
# API call # API call
@ -195,7 +196,10 @@ class Route(object):
except OSError as e: except OSError as e:
log.warning("Could not write to the record file {}: {}".format(record_file, e)) log.warning("Could not write to the record file {}: {}".format(record_file, e))
response = Response(request=request, route=route, output_schema=output_schema) response = Response(request=request, route=route, output_schema=output_schema)
if asyncio.iscoroutinefunction(func):
await func(request, response) await func(request, response)
else:
func(request, response)
except aiohttp.web.HTTPBadRequest as e: except aiohttp.web.HTTPBadRequest as e:
response = Response(request=request, route=route) response = Response(request=request, route=route)
response.set_status(e.status) response.set_status(e.status)