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:
		@@ -20,6 +20,7 @@ import functools
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
from taskflow import task as base
 | 
					from taskflow import task as base
 | 
				
			||||||
from taskflow import utils
 | 
					from taskflow import utils
 | 
				
			||||||
 | 
					from taskflow.utils import threading_utils
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def wraps(fn):
 | 
					def wraps(fn):
 | 
				
			||||||
@@ -43,6 +44,8 @@ def locked(*args, **kwargs):
 | 
				
			|||||||
        @wraps(f)
 | 
					        @wraps(f)
 | 
				
			||||||
        def wrapper(*args, **kwargs):
 | 
					        def wrapper(*args, **kwargs):
 | 
				
			||||||
            lock = getattr(args[0], attr_name)
 | 
					            lock = getattr(args[0], attr_name)
 | 
				
			||||||
 | 
					            if isinstance(lock, (tuple, list)):
 | 
				
			||||||
 | 
					                lock = threading_utils.MultiLock(locks=list(lock))
 | 
				
			||||||
            with lock:
 | 
					            with lock:
 | 
				
			||||||
                return f(*args, **kwargs)
 | 
					                return f(*args, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user