Created
November 18, 2011 02:04
-
-
Save shomah4a/1375327 to your computer and use it in GitHub Desktop.
lock decorator
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
#-*- 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