小编Rya*_*her的帖子

如何正确使用dask的upload_file()将本地代码传递给worker

我有一个local_code.py文件中的函数,我想通过 dask 传递给工作人员。我在这里看到问题的答案说这可以使用该upload_file()函数来完成,但我似乎无法让它工作,因为我仍然得到一个ModuleNotFoundError.

代码的相关部分如下。

from dask.distributed import Client
from dask_jobqueue import SLURMCluster

from local_code import *
helper_file = '/absolute/path/to/local_code.py'

def main():
    with SLURMCluster(**slurm_params) as cluster:

        cluster.scale(n_workers)

        with Client(cluster) as client:
            client.upload_file(helper_file)
            mapping = client.map(myfunc, data)
            client.gather(mapping)

if __name__ == '__main__':
    main()

Run Code Online (Sandbox Code Playgroud)

请注意,myfunc是从 导入的local_code,并且将其导入到地图没有错误。该函数myfunc还依赖于 中定义的其他函数local_code

使用此代码,我仍然收到此错误

distributed.protocol.pickle - INFO - Failed to deserialize b'\x80\x04\x95+\x00\x00\x00\x00\x00\x00\x00\x8c\x11local_code\x94\x8c\x$
Traceback (most recent call last):
  File "/home/gallagher.r/.local/lib/python3.7/site-packages/distributed/protocol/pickle.py", line 61, in loads
    return pickle.loads(x) …
Run Code Online (Sandbox Code Playgroud)

python dask dask-distributed

5
推荐指数
1
解决办法
1285
查看次数

标签 统计

dask ×1

dask-distributed ×1

python ×1