1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-10-18 09:00:07 +00:00

fix(vrtManager): modernize rwlock for Python 3.12 compatibility and add tests

This commit is contained in:
catborise 2026-09-24 21:49:52 +03:00
parent a26407176c
commit dc6327c554
3 changed files with 205 additions and 7 deletions

View file

@ -11,7 +11,7 @@ found at: http://code.activestate.com/recipes/502283-read-write-lock-class-rlock
# Imports
# -------
from threading import Condition, Lock, currentThread
from threading import Condition, Lock, current_thread
from time import time
# Read write lock
@ -71,7 +71,7 @@ class ReadWriteLock(object):
if timeout is not None:
endtime = time() + timeout
me = currentThread()
me = current_thread()
self.__condition.acquire()
try:
if self.__writer is me:
@ -121,7 +121,7 @@ class ReadWriteLock(object):
if timeout is not None:
endtime = time() + timeout
me, upgradewriter = currentThread(), False
me, upgradewriter = current_thread(), False
self.__condition.acquire()
try:
if self.__writer is me:
@ -196,7 +196,7 @@ class ReadWriteLock(object):
In case the current thread holds no lock, a ValueError is thrown."""
me = currentThread()
me = current_thread()
self.__condition.acquire()
try:
if self.__writer is me:
@ -206,7 +206,7 @@ class ReadWriteLock(object):
# No more write locks; take our writer position away and
# notify waiters of the new circumstances.
self.__writer = None
self.__condition.notifyAll()
self.__condition.notify_all()
elif me in self.__readers:
# We are a reader currently, take one nesting depth away.
self.__readers[me] -= 1
@ -216,7 +216,7 @@ class ReadWriteLock(object):
if not self.__readers:
# No more readers, notify waiters of the new
# circumstances.
self.__condition.notifyAll()
self.__condition.notify_all()
else:
raise ValueError("Trying to release unheld lock")
finally: