From 63ba5a8dc2aa4ec3e6f203b0ba4db249ecf0b00e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Wed, 27 Jul 2016 21:33:09 +0200 Subject: Rename helpers to music_sampler --- music_sampler/lock.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 music_sampler/lock.py (limited to 'music_sampler/lock.py') 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 @@ +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): + #debug_print("acquiring lock for {}".format(self.type)) + self.lock.acquire(*args, **kwargs) + + def release(self, *args, **kwargs): + #debug_print("releasing lock for {}".format(self.type)) + self.lock.release(*args, **kwargs) + -- cgit v1.2.3