From 8a443b1dbc69d9cae91b24dbb9e98e13fa33c3b5 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 9 Sep 2013 12:50:55 -0700 Subject: [PATCH] Allow the lock decorator to take a list In the cases where a list of locks is desired to be acquired it would be nice to use the same lock decorator to accomplish this. Change-Id: Ib25329eef330d1b434bc3e8e79d7bb38f450c7ae --- taskflow/decorators.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/taskflow/decorators.py b/taskflow/decorators.py index 8230eb1a..5a06d2aa 100644 --- a/taskflow/decorators.py +++ b/taskflow/decorators.py @@ -20,6 +20,7 @@ import functools from taskflow import task as base from taskflow import utils +from taskflow.utils import threading_utils def wraps(fn): @@ -43,6 +44,8 @@ def locked(*args, **kwargs): @wraps(f) def wrapper(*args, **kwargs): lock = getattr(args[0], attr_name) + if isinstance(lock, (tuple, list)): + lock = threading_utils.MultiLock(locks=list(lock)) with lock: return f(*args, **kwargs)