[client.upload_file()对于嵌套模块

问题描述 投票:1回答:1

我的项目结构如下;

- topmodule/
   - childmodule1/
      -  my_func1.py
   - childmodule2/
      -  my_func2.py
   - common.py
   - __init__.py

从我在Dask群集边缘节点上的Jupyter笔记本中,执行以下操作

from topmodule.childmodule1.my_func1 import MyFuncClass1
from topmodule.childmodule2.my_func2 import MyFuncClass2

然后,我正在创建一个分布式客户端并按以下方式发送工作;

client = Client(YarnCluster())
client.submit(MyFuncClass1.execute)

此错误出来,因为工作人员没有topmodule的文件。

"/mnt1/yarn/usercache/hadoop/appcache/application_1572459480364_0007/container_1572459480364_0007_01_000003/environment/lib/python3.7/site-packages/distributed/protocol/pickle.py", line 59, in loads return pickle.loads(x) ModuleNotFoundError: No module named 'topmodule'

所以我想做的是-我尝试上传“ topmodule”下的每个文件。直接在“ topmodule”下的文件似乎已上传,但嵌套的文件未上传。以下是我在说的;

代码:

from pathlib import Path

for filename in Path('topmodule').rglob('*.py'):
    print(filename)
    client.upload_file(filename)

控制台输出:

topmodule/common.py # processes fine 
topmodule/__init__.py # processes fine 
topmodule/childmodule1/my_func1.py # throws error

追踪:


---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-13-dbf487d43120> in <module>
      3 for filename in Path('nodes').rglob('*.py'):
      4     print(filename)
----> 5     client.upload_file(filename)

~/miniconda/lib/python3.7/site-packages/distributed/client.py in upload_file(self, filename, **kwargs)
   2929         )
   2930         if isinstance(result, Exception):
-> 2931             raise result
   2932         else:
   2933             return result

ModuleNotFoundError: No module named 'topmodule'

我的问题是-如何将整个模块及其文件上传到工作人员?我们的模块很大,因此我想避免只是为了这个问题而对其进行重组,除非我们构建该模块的方式存在根本性的缺陷。

或者-是否有更好的方法让所有敏捷工作者从git存储库中了解模块?

dask dask-distributed
1个回答
0
投票

当分别在每个文件上调用upload_file时,您会丢失模块的目录结构。

如果您要上传更全面的模块,则可以将其打包为zip或egg文件,然后上传。

https://docs.dask.org/en/latest/futures.html#distributed.Client.upload_file

© www.soinside.com 2019 - 2024. All rights reserved.