#NEWLINE# def only_one( key = '' , timeout = None ) : #NEWLINE# #INDENT# 'Enforce only one celery task at a time.' #NEWLINE# def real_decorator( function ) : #NEWLINE# #INDENT# 'Decorator.' #NEWLINE# @ wraps ( function ) #NEWLINE# def wrapper( * args , **kwargs ) : #NEWLINE# #INDENT# 'Caller.' #NEWLINE# have_lock = False #NEWLINE# lock = REDIS_CLIENT . lock ( key , timeout = timeout ) #NEWLINE# try : #NEWLINE# #INDENT# have_lock = lock . acquire ( blocking = False ) #NEWLINE# if have_lock : #NEWLINE# #INDENT# function ( * args , ** kwargs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# LOG . info ( ( 'key %s locked...' % key ) ) #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# if have_lock : #NEWLINE# #INDENT# lock . release ( ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return wrapper #NEWLINE# #UNINDENT# return timeout