mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-06 15:21:13 +02:00
Garbage collect the lock
This commit is contained in:
1 parent
545acd1f06
commit
7c2329d870
2 files changed
+9
-11
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user