def wrapper(*args, **kwargs): # NOTE(dtantsur): this code could be written simpler, but then unit # testing decorated functions is pretty hard, as we usually pass a Mock # object instead of TaskManager there. if len(args) > 1: task = args[1] if isinstance(args[1], TaskManager) else args[0] else: task = args[0] if task.shared: raise exception.ExclusiveLockRequired() return f(*args, **kwargs)
def wrapper(*args, **kwargs): # NOTE(dtantsur): this code could be written simpler, but then unit # testing decorated functions is pretty hard, as we usually pass a Mock # object instead of TaskManager there. if len(args) > 1: task = args[1] if isinstance(args[1], TaskManager) else args[0] else: task = args[0] if task.shared: raise exception.ExclusiveLockRequired() # NOTE(lintan): This is a workaround to set the context of async tasks, # which should contain an exclusive lock. task.context.ensure_thread_contain_context() return f(*args, **kwargs)
def wrapper(*args, **kwargs): task = args[0] if isinstance(args[0], TaskManager) else args[1] if task.shared: raise exception.ExclusiveLockRequired() return f(*args, **kwargs)