parallel/serial execute accepts several arguments now
This commit is contained in:
@ -1,20 +1,21 @@
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
|
||||
def parallel(func, targets, names=None):
|
||||
def parallel(func, *targets, names=None):
|
||||
with ThreadPoolExecutor() as executor:
|
||||
results = executor.map(func, targets)
|
||||
if names:
|
||||
results = executor.map(func, *targets)
|
||||
if names is not None:
|
||||
return dict(zip(names, results))
|
||||
else:
|
||||
return list(results)
|
||||
|
||||
|
||||
def serial(func, targets, names=None):
|
||||
if names:
|
||||
return {n: func(t) for n, t in zip(names, targets)}
|
||||
def serial(func, *targets, names=None):
|
||||
targets = zip(*targets)
|
||||
if names is not None:
|
||||
return {n: func(*t) for n, t in zip(names, targets)}
|
||||
else:
|
||||
return [func(t) for t in targets]
|
||||
return [func(*t) for t in targets]
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user