]> git.immae.eu Git - perso/Immae/Projets/Python/MusicSampler.git/blame - music_sampler/lock.py
Rename helpers to music_sampler
[perso/Immae/Projets/Python/MusicSampler.git] / music_sampler / lock.py
CommitLineData
ba9ea93a
IB
1import threading
2
a24c34bc
IB
3from . import debug_print
4
ba9ea93a
IB
5class Lock:
6 def __init__(self, lock_type):
7 self.type = lock_type
8 self.lock = threading.RLock()
9
29597680
IB
10 def __enter__(self, *args, **kwargs):
11 self.acquire(*args, **kwargs)
12
13 def __exit__(self, type, value, traceback, *args, **kwargs):
14 self.release(*args, **kwargs)
15
ba9ea93a 16 def acquire(self, *args, **kwargs):
a24c34bc 17 #debug_print("acquiring lock for {}".format(self.type))
ba9ea93a
IB
18 self.lock.acquire(*args, **kwargs)
19
20 def release(self, *args, **kwargs):
a24c34bc 21 #debug_print("releasing lock for {}".format(self.type))
ba9ea93a
IB
22 self.lock.release(*args, **kwargs)
23