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
This commit is contained in:
Joshua Harlow
2013-09-09 12:50:55 -07:00
parent 7c2aeaed36
commit 8a443b1dbc

View File

@@ -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)