Skip to content

Instantly share code, notes, and snippets.

@afonasev
Created March 14, 2018 09:48
Show Gist options
  • Save afonasev/a5a2c08dbb79d517c264098f4cf7689f to your computer and use it in GitHub Desktop.
Save afonasev/a5a2c08dbb79d517c264098f4cf7689f to your computer and use it in GitHub Desktop.
Synchronized method with mutex
def synchronized_method(mutex_attr='mutex'):
def decorator(method):
@wraps(method)
def wrapped(instance, *args, **kw):
with getattr(instance, mutex_attr):
return method(instance, *args, **kw)
return wrapped
return decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment