-
-
Save afonasev/a5a2c08dbb79d517c264098f4cf7689f to your computer and use it in GitHub Desktop.
Synchronized method with mutex
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 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