Python 如何将源文件传输到Dask工作人员?
在dask jupyter节点上,我有以下文件布局:Python 如何将源文件传输到Dask工作人员?,python,dask,Python,Dask,在dask jupyter节点上,我有以下文件布局: main/ src/ subfolder/ file1.py file2.py file3.py main.py main.py中的代码大致如下: # main.py from distributed import Client from src.subfolder.file1 import important_function # ... cluster_address = os.e
main/
src/
subfolder/
file1.py
file2.py
file3.py
main.py
main.py
中的代码大致如下:
# main.py
from distributed import Client
from src.subfolder.file1 import important_function
# ...
cluster_address = os.environ.get('CLUSTER_ADDRESS', 'dask-scheduler:8786')
client = Client(cluster_address)
arg1, arg2 = ...
future = client.submit(important_function, arg1, arg2)
result = future.result()
事实上,这个故事更复杂,因为我从一个模板创建了dask workers。但无论如何,我认为这说明了问题所在。运行此代码时,会收到以下错误消息:
Traceback (most recent call last):
...
File "main.py", line 151, in ...
result = future.result()
File "/opt/conda/lib/python3.7/site-packages/distributed/client.py", line 222, in result
raise exc.with_traceback(tb)
File "/opt/conda/lib/python3.7/site-packages/distributed/protocol/pickle.py", line 59, in loads
return pickle.loads(x)
ModuleNotFoundError: No module named 'src'
我尝试的是:我在生成worker时将所有源文件夹复制到worker。所有源文件都位于辅助程序的
/build
中。因此,上面示例中的main
的全部内容实际上都在worker上的目录/build
中。我想我需要告诉工作者,它接收的函数应该在/build
中作为他们的工作目录执行。这是路吗?有人对如何解决这个问题有什么想法吗?好的,我想出来了。在重要函数()中
我必须像这样附加到sys路径:
def important_function(arg1, arg2):
sys.path.append("/build")
# more import statements here