aboutsummaryrefslogblamecommitdiff
path: root/helpers/lock.py
blob: 85d281ac8e576731e0362e67a36ad19d15c508da (plain) (tree)
1
2
3
4
5
6
7






                                     





                                                                







                                                         
import threading

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):
        #print("acquiring lock for {}".format(self.type))
        self.lock.acquire(*args, **kwargs)

    def release(self, *args, **kwargs):
        #print("releasing lock for {}".format(self.type))
        self.lock.release(*args, **kwargs)