parallel/serial execute accepts several arguments now
This commit is contained in:
@ -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?
|
||||
|
@ -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