Ipython 并行脚本 运行 和 return 局部变量
Ipython parallel scripts running and return the local variables
例如,我 运行 4 个脚本顺序:
%run -i script1.py
%run -i script2.py
%run -i script3.py
%run -i script4.py
每次执行的时间都挺长的。 iPython notebook 中有什么方法可以 运行 并行脚本 和 return 来自所有脚本的局部变量 (2 或 3 个变量是重要的)?在顺序执行中,它工作正常但时间长。先感谢您。
我尝试应用此 topic 中的代码,但卡在了第一部分:
def my_func(my_file):
!python pgm.py my_file
或者在我的情况下:
def my_func(my_file):
%run -i $my_file
我可以看到正在执行代码,但在此之后我无法从这些脚本中看到局部变量。
假设您启动了 4 个引擎,您将在每个引擎上发送 4 个脚本。
做完后
rc = parallel.Client()
view = rc.load_balanced_view()
r = view.map_async(my_func, ["script1.py", "script2.py", "script3.py", "script4.py"])
完成后,您可以访问变量 a
和 b
以及 pull
:
var = rc[:].pull(["a","b"])
var.result # or var.r or var.result_dict
[[10, 12020.2], [11, 14], [1, 0], [1, 14425]]
对应每个脚本的运行后的a
和b
的值。
所以在 script1.py
中,最后,您有 a==10
和 b==12020.2
。
希望这对您有所帮助。
对了,我把你说的link稍微编辑了一下,有个小错误:
def my_func(my_file):
!python pgm.py my_file
应该是:
def my_func(my_file):
!python pgm.py {my_file}
例如,我 运行 4 个脚本顺序:
%run -i script1.py
%run -i script2.py
%run -i script3.py
%run -i script4.py
每次执行的时间都挺长的。 iPython notebook 中有什么方法可以 运行 并行脚本 和 return 来自所有脚本的局部变量 (2 或 3 个变量是重要的)?在顺序执行中,它工作正常但时间长。先感谢您。
我尝试应用此 topic 中的代码,但卡在了第一部分:
def my_func(my_file):
!python pgm.py my_file
或者在我的情况下:
def my_func(my_file):
%run -i $my_file
我可以看到正在执行代码,但在此之后我无法从这些脚本中看到局部变量。
假设您启动了 4 个引擎,您将在每个引擎上发送 4 个脚本。
做完后
rc = parallel.Client()
view = rc.load_balanced_view()
r = view.map_async(my_func, ["script1.py", "script2.py", "script3.py", "script4.py"])
完成后,您可以访问变量 a
和 b
以及 pull
:
var = rc[:].pull(["a","b"])
var.result # or var.r or var.result_dict
[[10, 12020.2], [11, 14], [1, 0], [1, 14425]]
对应每个脚本的运行后的a
和b
的值。
所以在 script1.py
中,最后,您有 a==10
和 b==12020.2
。
希望这对您有所帮助。
对了,我把你说的link稍微编辑了一下,有个小错误:
def my_func(my_file):
!python pgm.py my_file
应该是:
def my_func(my_file):
!python pgm.py {my_file}