Python 解包元组列表的dask延迟对象
我有一个函数返回两个元素的元组。使用pool starmap调用该函数以生成元组列表,这些元组被解压为两个列表Python 解包元组列表的dask延迟对象,python,multiprocessing,dask,Python,Multiprocessing,Dask,我有一个函数返回两个元素的元组。使用pool starmap调用该函数以生成元组列表,这些元组被解压为两个列表 def func(): #...some operations return (x,y) def MP_a_func(func,iterable,proc,chunk): pool=multiprocessing.Pool(processes=proc) Result=pool.starmap(func,iterable,chunksize=chunk)
def func():
#...some operations
return (x,y)
def MP_a_func(func,iterable,proc,chunk):
pool=multiprocessing.Pool(processes=proc)
Result=pool.starmap(func,iterable,chunksize=chunk)
pool.close()
return Result
##
if __name__ == '__main__':
results=MP_a_func(func,iterable,proc,chunk)
a,b=zip(*results)
我现在希望使用daskdelayed
API,如下所示
if __name__ == '__main__':
results=delayed(MP_a_func(func,iterable,proc,chunk))
不使用results.compute()
,是否可以解压延迟对象中的元组
感谢您的帮助另一个延迟函数可以解包元组,在下面的示例中,
返回\u元组(1)
的延迟值未计算,而是作为延迟的
对象传递:
导入dask
@达斯克
def返回值(x):
返回x+1,x-1
@达斯克
def process_first_项目(某些元组):
返回一些元组[0]+10
结果=处理第一项(返回元组(1))
dask.compute(结果)
根据@mdurant的回答,原来
delayed
function/decorator有nout
参数,另请参见。另一个延迟函数可以解包元组,在下面的示例中,return\u tuple(1)
的延迟值没有计算,而是作为delayed
对象传递:
导入dask
@达斯克
def返回值(x):
返回x+1,x-1
@达斯克
def process_first_项目(某些元组):
返回一些元组[0]+10
结果=处理第一项(返回元组(1))
dask.compute(结果)
根据@mdurant的回答,
delayed
function/decorator有nout
参数,另请参见。如果您知道输出的数量,那么delayed
函数(或decorator)会使用一个可选的nout
参数,这会将单个延迟的输出拆分为多个延迟的输出。这听起来正是您所需要的。如果您知道输出的数量,延迟的
函数(或decorator)使用可选的nout
参数,这将把单个延迟的输出拆分为多个延迟的输出。这听起来正是您所需要的。有趣的是,我以前没有见过这个,但事实证明它已经存在了很长一段时间:有趣的是,我以前没有见过这个,但事实证明它存在了很长一段时间: