X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=helpers%2Flock.py;h=85d281ac8e576731e0362e67a36ad19d15c508da;hb=29597680758e4924aa71fc021465189e153f2016;hp=dff8b1fb87ad373c58370113339a6114ce255b4e;hpb=9b9dd12a0253f2e65c5934068d91b544f7679f12;p=perso%2FImmae%2FProjets%2FPython%2FMusicSampler.git diff --git a/helpers/lock.py b/helpers/lock.py index dff8b1f..85d281a 100644 --- a/helpers/lock.py +++ b/helpers/lock.py @@ -5,6 +5,12 @@ class Lock: self.type = lock_type self.lock = threading.RLock() + def __enter__(self, *args, **kwargs): + self.acquire(*args, **kwargs) + + def __exit__(self, type, value, traceback, *args, **kwargs): + self.release(*args, **kwargs) + def acquire(self, *args, **kwargs): #print("acquiring lock for {}".format(self.type)) self.lock.acquire(*args, **kwargs)