]>
Commit | Line | Data |
---|---|---|
ba9ea93a IB |
1 | import threading |
2 | ||
3 | class Lock: | |
4 | def __init__(self, lock_type): | |
5 | self.type = lock_type | |
6 | self.lock = threading.RLock() | |
7 | ||
29597680 IB |
8 | def __enter__(self, *args, **kwargs): |
9 | self.acquire(*args, **kwargs) | |
10 | ||
11 | def __exit__(self, type, value, traceback, *args, **kwargs): | |
12 | self.release(*args, **kwargs) | |
13 | ||
ba9ea93a IB |
14 | def acquire(self, *args, **kwargs): |
15 | #print("acquiring lock for {}".format(self.type)) | |
16 | self.lock.acquire(*args, **kwargs) | |
17 | ||
18 | def release(self, *args, **kwargs): | |
19 | #print("releasing lock for {}".format(self.type)) | |
20 | self.lock.release(*args, **kwargs) | |
21 |