Skip to content

Instantly share code, notes, and snippets.

@koreyou
Last active September 9, 2017 05:09
Show Gist options
  • Save koreyou/0a4d37eca730798d1b7157db3f6bfb5a to your computer and use it in GitHub Desktop.
Save koreyou/0a4d37eca730798d1b7157db3f6bfb5a to your computer and use it in GitHub Desktop.
lock decorator
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