aboutsummaryrefslogtreecommitdiff
path: root/music_sampler/lock.py
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-27 21:33:09 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2016-07-27 21:33:09 +0200
commit63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e (patch)
treef043ab215425aca3434bf178029dad9f9e62dbe9 /music_sampler/lock.py
parent35bde798b6cda13579337b0ec5a803fdd5eab19a (diff)
downloadMusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.tar.gz
MusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.tar.zst
MusicSampler-63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e.zip
Rename helpers to music_sampler
Diffstat (limited to 'music_sampler/lock.py')
-rw-r--r--music_sampler/lock.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/music_sampler/lock.py b/music_sampler/lock.py
new file mode 100644
index 0000000..9beafcd
--- /dev/null
+++ b/music_sampler/lock.py
@@ -0,0 +1,23 @@
1import threading
2
3from . import debug_print
4
5class Lock:
6 def __init__(self, lock_type):
7 self.type = lock_type
8 self.lock = threading.RLock()
9
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
16 def acquire(self, *args, **kwargs):
17 #debug_print("acquiring lock for {}".format(self.type))
18 self.lock.acquire(*args, **kwargs)
19
20 def release(self, *args, **kwargs):
21 #debug_print("releasing lock for {}".format(self.type))
22 self.lock.release(*args, **kwargs)
23