Last active
September 9, 2017 05:09
-
-
Save koreyou/0a4d37eca730798d1b7157db3f6bfb5a to your computer and use it in GitHub Desktop.
lock decorator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lock(f): | |
""" decorator which locks class method | |
You need property _lock defined as in the following. | |
self._lock = threading.Lock() | |
""" | |
def body(self, *args, **kwargs): | |
with self._lock: | |
return f(self, *args, **kwargs) | |
return body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment