mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-23 23:38:21 +00:00
Garbage collect the lock
This commit is contained in:
parent
545acd1f06
commit
7c2329d870
@ -47,12 +47,3 @@ class VersionHandler:
|
||||
if request.json["version"] != __version__:
|
||||
raise HTTPConflict(text="Client version {} differs with server version {}".format(request.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__})
|
||||
|
@ -163,9 +163,16 @@ class Route(object):
|
||||
vm_id = request.match_info.get("vm_id")
|
||||
if vm_id is None:
|
||||
vm_id = request.match_info["device_id"]
|
||||
cls._vm_locks.setdefault(vm_id, asyncio.Lock())
|
||||
with (yield from cls._vm_locks[vm_id]):
|
||||
cls._vm_locks.setdefault(vm_id, {"lock": asyncio.Lock(), "concurrency": 0})
|
||||
cls._vm_locks[vm_id]["concurrency"] += 1
|
||||
|
||||
with (yield from cls._vm_locks[vm_id]["lock"]):
|
||||
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:
|
||||
response = yield from control_schema(request)
|
||||
return response
|
||||
|
Loading…
Reference in New Issue
Block a user