4

希望这有一个我在阅读文档时错过的直截了当的答案。以下是问题 -

  1. 我在启动时在所有 ipengine(s) 上加载了一个模块
  2. 我已经对模块进行了更改
  3. 我希望将这些更改传播到远程 ipengine(s),即我希望在所有远程实例中重新加载模块

如何实现?

4

3 回答 3

2

您还可以使用以下命令打开引擎上的 ipython 自动重载功能:

%px %load_ext autoreload
%px %autoreload 2

请注意,此解决方案和使用 dview.execute() 调用 reload 当新引擎稍后可以上线时(如在集群上使用批处理调度程序时)都有问题:它们仅在当前存在的引擎上执行。

另一个问题:您可能需要深度(递归)重新加载。请参阅 ipengine 的此选项:

--ZMQInteractiveShell.deep_reload=<CBool>
Default: False
Enable deep (recursive) reloading by default. IPython can use the
deep_reload module which reloads changes in modules recursively (it replaces
the reload() function, so you don't need to change anything to use it).
deep_reload() forces a full reload of modules whose code may have changed,
which the default reload() function does not.  When deep_reload is off,
IPython will use the normal reload(), but deep_reload will still be
available as dreload().
于 2014-09-15T16:57:45.530 回答
1

这是我找到的答案,不确定这是否是最好的方法

from IPython.parallel import Client
rc = Client(profile='ssh')
dview = rc[:]
dview.execute('reload(<module>)', block = True)
于 2013-04-18T20:12:28.913 回答
0

我遇到了同样的问题,我正在开发一个我想在远程引擎上测试的模块,但我不想将我的更改提交给 git,然后在每次远程重新加载之前拉动引擎机器上的更改。

可能有更好的方法来做到这一点,但我的解决方案是编写一个简单的帮助模块,它可以很容易地通过 scp 将正在进行的代码传送到引擎。

我将在这里复制使用示例:

import IPython.parallel
import ishuttle
import my_module as mm

# Create a client for the cluster with remote engines
rc = IPython.parallel.Client(profile='remote_ssh_engines')
dview = rc[:]

# Create a shuttle object; the engines' working directory
# is switched to '/Remote/engine/server/scratch' after its creation
s = ishuttle.Shuttle(rc, '/Remote/engine/server/scratch')

# Make my_module available on all engines as mm. This code scp's the
# module over, imports it as mm, then reloads it.
s.remote_import('my_module', import_as='mm')

# Apply our favourite function from our favourite module
dview.apply_sync(mm.my_func, 'favourite argument for my_func')
于 2014-05-26T19:21:49.523 回答