2

I want to use self.something as a parameter of decorator. like this:

def synchronized(lock):
    def decorator(func):
        def wrapper(*args, **kwargs):
            with lock:
                func(*args, **kwargs)
        return wrapper
    return decorator

class A:
    def __init__(self):
        self.lock = Lock()

    @synchronized(self.lock)
    def test(self):
        pass

but I can't use self in this situation. plz help me.

leejun
  • 61
  • 3
  • 2
    See https://stackoverflow.com/questions/11731136/python-class-method-decorator-with-self-arguments – Thierry Lathuille Dec 29 '19 at 14:45
  • 2
    Per Thierry Lathuille, does this answer your question? [Python class method decorator with self arguments?](https://stackoverflow.com/questions/11731136/python-class-method-decorator-with-self-arguments) – Davis Herring Dec 29 '19 at 17:37

0 Answers0