Skip to content

Instantly share code, notes, and snippets.

@atdt
Created August 17, 2011 20:38
Show Gist options
  • Save atdt/1152549 to your computer and use it in GitHub Desktop.
Save atdt/1152549 to your computer and use it in GitHub Desktop.
decorator to lock and unlock a method
# 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