1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-24 15:58:08 +00:00

Garbage collect the lock

This commit is contained in:
Julien Duponchelle 2015-02-25 11:19:16 +01:00
parent 545acd1f06
commit 7c2329d870
2 changed files with 9 additions and 11 deletions

View File

@ -47,12 +47,3 @@ class VersionHandler:
if request.json["version"] != __version__: if request.json["version"] != __version__:
raise HTTPConflict(text="Client version {} differs with server version {}".format(request.json["version"], __version__)) raise HTTPConflict(text="Client version {} differs with server version {}".format(request.json["version"], __version__))
response.json({"version": __version__}) response.json({"version": __version__})
@staticmethod
@Route.get(
r"/sleep/{vm_id}",
description="Retrieve the server version number",
output=VERSION_SCHEMA)
def sleep(request, response):
yield from asyncio.sleep(1)
response.json({"version": __version__})

View File

@ -163,9 +163,16 @@ class Route(object):
vm_id = request.match_info.get("vm_id") vm_id = request.match_info.get("vm_id")
if vm_id is None: if vm_id is None:
vm_id = request.match_info["device_id"] vm_id = request.match_info["device_id"]
cls._vm_locks.setdefault(vm_id, asyncio.Lock()) cls._vm_locks.setdefault(vm_id, {"lock": asyncio.Lock(), "concurrency": 0})
with (yield from cls._vm_locks[vm_id]): cls._vm_locks[vm_id]["concurrency"] += 1
with (yield from cls._vm_locks[vm_id]["lock"]):
response = yield from control_schema(request) response = yield from control_schema(request)
cls._vm_locks[vm_id]["concurrency"] -= 1
# No more waiting requests, garbage collect the lock
if cls._vm_locks[vm_id]["concurrency"] <= 0:
del cls._vm_locks[vm_id]
else: else:
response = yield from control_schema(request) response = yield from control_schema(request)
return response return response