Created
August 17, 2011 20:38
-
-
Save atdt/1152549 to your computer and use it in GitHub Desktop.
decorator to lock and unlock a method
This file contains 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
# via shove (in pypi) | |
def synchronized(func): | |
'''Decorator to lock and unlock a method (Phillip J. Eby). | |
@param func Method to decorate | |
''' | |
def wrapper(self, *__args, **__kw): | |
self._lock.acquire() | |
try: | |
return func(self, *__args, **__kw) | |
finally: | |
self._lock.release() | |
wrapper.__name__ = func.__name__ | |
wrapper.__dict__ = func.__dict__ | |
wrapper.__doc__ = func.__doc__ | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment