Skip to content

Commit

Permalink
Fix bugs with parallel exec. (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximelb committed Sep 23, 2022
1 parent a590f10 commit 5b755db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lcservice/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,7 @@ def parallelExec( self, f, objects, timeout = None, maxConcurrent = None ):

results = []
with ThreadPoolExecutor( max_workers=maxConcurrent ) as executor:
future = executor.map( lambda o: self._retExecOrExc( f, o, timeout ), objects, timeout = timeout )
results = future.result()
results = executor.map( lambda o: self._retExecOrExc( f, o, timeout ), objects, timeout = timeout )
return list( results )

def _retExecOrExc( self, f, o, timeout ):
Expand Down Expand Up @@ -500,8 +499,7 @@ def parallelExecEx( self, f, objects, timeout = None, maxConcurrent = None ):

results = []
with ThreadPoolExecutor( max_workers=maxConcurrent ) as executor:
future = executor.map( lambda o: self._retExecOrExcWithKey( f, o, timeout ), objects.items(), timeout = timeout )
results = future.result()
results = executor.map( lambda o: self._retExecOrExcWithKey( f, o, timeout ), objects.items(), timeout = timeout )
return list( results )

# LC Service Lifecycle Functions
Expand Down
14 changes: 14 additions & 0 deletions tests/test_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,18 @@ def _inc():
time.sleep( 2.1 )
assert( 3 == n )

svc._onShutdown()

def test_parallel():
global n
svc = lcservice.Service( 'test-service', None )

n = 0
def _inc():
global n
n += 1

res = svc.parallelExec( _inc, [ 1, 2, 3, 4 ], 10, 5 )
assert( 4 == len( res ) )

svc._onShutdown()

0 comments on commit 5b755db

Please sign in to comment.