def memcache_lock(prefix, expires=(60 * 60)):
 def decorator(func):
  @functools.wraps(func)
  def wrapper(self, *args, **kwargs):
   name = '_'.join(((prefix, func.__name__) + args))
   lock = MemcacheLock(name, expires=expires)
   if lock.locked():
    log.warning(('Lock %s locked; ignoring call.' % name))
    return
   try:
    lock.acquire()
   except MemcacheLockException:
    log.warning(('Aborting %s; lock acquisition failed.' % name))
    return
   else:
    try:
     return func(self, *args, **kwargs)
    finally:
     lock.release()
  return wrapper
 return decorator

def memcache_lock ( prefix , expires = ( 60 * 60 ) ) : def decorator ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : name = '_' . join ( ( ( prefix , func . __name__ ) + args ) ) lock = MemcacheLock ( name , expires = expires ) if lock . locked ( ) : log . warning ( ( 'Lock %s locked; ignoring call.' % name ) ) return try : lock . acquire ( ) except MemcacheLockException : log . warning ( ( 'Aborting %s; lock acquisition failed.' % name ) ) return else : try : return func ( self , * args , ** kwargs ) finally : lock . release ( ) return wrapper return decorator
decorator that only allows one instance of the same command to run at a time .