]>
Commit | Line | Data |
---|---|---|
1 | import threading | |
2 | ||
3 | from . import debug_print | |
4 | ||
5 | class 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 |