]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blobdiff - helpers/lock.py
Move actions to separate files
[perso/Immae/Projets/Python/MusicSampler.git] / helpers / lock.py
index dff8b1fb87ad373c58370113339a6114ce255b4e..9beafcde60c80b789b46839ae462c71245727593 100644 (file)
@@ -1,15 +1,23 @@
 import threading
 
+from . import debug_print
+
 class Lock:
     def __init__(self, lock_type):
         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))
+        #debug_print("acquiring lock for {}".format(self.type))
         self.lock.acquire(*args, **kwargs)
 
     def release(self, *args, **kwargs):
-        #print("releasing lock for {}".format(self.type))
+        #debug_print("releasing lock for {}".format(self.type))
         self.lock.release(*args, **kwargs)