Skip to content

Instantly share code, notes, and snippets.

@shomah4a
Created November 18, 2011 02:04
Show Gist options
  • Save shomah4a/1375327 to your computer and use it in GitHub Desktop.
Save shomah4a/1375327 to your computer and use it in GitHub Desktop.
lock decorator
#-*- coding:utf-8 -*-
try:
import threading
except ImportError:
import dummy_threading as threading
LOCK_OBJECT = threading.RLock()
def lock(lock=LOCK_OBJECT):
def decorator(f):
def call(*args, **argd):
with lock:
return f(*args, **argd)
return call
return decorator
@lock()
def synchronized():
return 10
print synchronized()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment