File tree Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Expand file tree Collapse file tree 3 files changed +17
-9
lines changed Original file line number Diff line number Diff line change 77import logging
88import threading
99
10- from ..dag import walk , ThreadedWalker
10+ from ..dag import walk , ThreadedWalker , UnlimitedSemaphore
1111from ..plan import Step , build_plan , build_graph
1212
1313import botocore .exceptions
@@ -53,7 +53,12 @@ def build_walker(concurrency):
5353 """
5454 if concurrency == 1 :
5555 return walk
56- return ThreadedWalker (concurrency ).walk
56+
57+ semaphore = UnlimitedSemaphore ()
58+ if concurrency > 1 :
59+ semaphore = threading .Semaphore (concurrency )
60+
61+ return ThreadedWalker (semaphore ).walk
5762
5863
5964def plan (description , stack_action , context ,
Original file line number Diff line number Diff line change @@ -414,14 +414,12 @@ class ThreadedWalker(object):
414414 allows, using threads.
415415
416416 Args:
417- semaphore (threading.Semaphore, optional ): a semaphore object which
417+ semaphore (threading.Semaphore): a semaphore object which
418418 can be used to control how many steps are executed in parallel.
419- By default, there is not limit to the amount of parallelism,
420- other than what the graph topology allows.
421419 """
422420
423- def __init__ (self , semaphore = None ):
424- self .semaphore = semaphore or UnlimitedSemaphore ()
421+ def __init__ (self , semaphore ):
422+ self .semaphore = semaphore
425423
426424 def walk (self , dag , walk_func ):
427425 """ Walks each node of the graph, in parallel if it can.
Original file line number Diff line number Diff line change 55
66from nose import with_setup
77from nose .tools import nottest , raises
8- from stacker .dag import DAG , DAGValidationError , ThreadedWalker
8+ from stacker .dag import (
9+ DAG ,
10+ DAGValidationError ,
11+ ThreadedWalker ,
12+ UnlimitedSemaphore
13+ )
914import threading
1015
1116dag = None
@@ -220,7 +225,7 @@ def test_transitive_deep_reduction():
220225@with_setup (blank_setup )
221226def test_threaded_walker ():
222227 dag = DAG ()
223- walker = ThreadedWalker ()
228+ walker = ThreadedWalker (UnlimitedSemaphore () )
224229
225230 # b and c should be executed at the same time.
226231 dag .from_dict ({'a' : ['b' , 'c' ],
You can’t perform that action at this time.
0 commit comments