parallel/serial execute accepts several arguments now

This commit is contained in:
2020-11-02 14:43:20 +01:00
parent f0fda94766
commit 9096961de6
2 changed files with 9 additions and 8 deletions

View File

@ -24,7 +24,7 @@ def run_check(clargs):
get_data = DataGetter(clargs.timeout, clargs.quiet)
run = serial if clargs.serial else parallel
data = run(get_data, pvs, chans)
data = run(get_data, pvs, names=chans)
df = pd.DataFrame(data).T
df = df.infer_objects() #TODO: why is this needed?

View File

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