TL;DR:,我无法让最基本的dispy示例代码正常运行。为什么不行?
详细信息:
我试图进入python中的分布式处理,并认为平淡库听起来很有趣,因为它提供了全面的特性集。
然而,我一直试图遵循他们的基本规范程序示例,但我没有得到任何进展。
python -m pip install dispy)python dispynode.py。它似乎起作用了,因为我得到了以下输出: 2016-06-14 10:33:38
2016-06-14 10:33:38带有epoll I/O通知器的版本4.1
2016-06-14 10:33:38 -服务8个cpus :10.0.48.54:51348输入“退出”或“退出”以终止析取节点,“停止”终止
服务,“启动”以重新启动服务,“CPU”用于更改所使用的CPU,
任何其他的东西都能得到地位:# function 'compute' is distributed and executed with arguments
# supplied with 'cluster.submit' below
def compute(n):
import time, socket
time.sleep(n)
host = socket.gethostname()
return (host, n)
if __name__ == '__main__':
# executed on client only; variables created below, including modules imported,
# are not available in job computations
import dispy, random
# distribute 'compute' to nodes; 'compute' does not have any dependencies (needed from client)
cluster = dispy.JobCluster(compute)
# run 'compute' with 20 random numbers on available CPUs
jobs = []
for i in range(20):
job = cluster.submit(random.randint(5,20))
job.id = i # associate an ID to identify jobs (if needed later)
jobs.append(job)
# cluster.wait() # waits until all jobs finish
for job in jobs:
host, n = job() # waits for job to finish and returns results
print('%s executed job %s at %s with %s' % (host, job.id, job.start_time, n))
# other fields of 'job' that may be useful:
# job.stdout, job.stderr, job.exception, job.ip_addr, job.end_time
cluster.print_status() # shows which nodes executed how many jobs etc.当我运行这个(python sample.py)时,它就挂起了。通过pdb进行调试,我看到它最终被挂在dispy/__init__.py(117)__call__()上。这一行写着self.finish.wait()。当wait()进入lib/python3.5/threading.py(531)wait()时,finish只是一个python线程。它一碰到等待就挂起来了。
我尝试在客户端机器上运行dispynode,并得到了相同的结果。我尝试了许多将节点传递到集群创建中的变体,例如:
cluster = dispy.JobCluster(compute, nodes=['localhost'])
cluster = dispy.JobCluster(compute, nodes=['*'])
cluster = dispy.JobCluster(compute, nodes=[<hostname of the remote node running the client>])我试着不加注释地运行cluster.wait()行,并得到了相同的结果。
当我添加日志记录(cluster = dispy.JobCluster(compute, loglevel = 10))时,我在客户端得到了以下输出:
2016-06-14 10:27:01带有epoll I/O通知器的版本4.1 2016-06-14 10:27:27:01 dispy客户端:51347 2016-06-14 10:27:01在"_dispy_20160614102701“中存储故障恢复信息 2016-06-14 10:27:01冷静-待业:0 2016-06-14 10:27:01冷静-待业:1 2016-06-14 10:27:01冷静-待业:2 2016-06-14 10:27:01冷静-待业:3 2016-06-14 10:27:01冷静-待业:4 2016-06-14 10:27:01冷静-待业:5 2016-06-14 10:27:01冷静-待业:6 2016-06-14 10:27:01冷静-待业:7 2016-06-14 10:27:01冷静-待业:8 2016-06-14 10:27:01冷静-待业:9 2016-06-14 10:27:01冷静-待业: 10
这似乎并不令人意外,但并不能帮助我理解为什么这些工作没有运行。
关于它的价值,下面是_dispy_20160614102701.bak:
“_群集”,(0,207) “计算1465918021755”,(512,85)
类似地,_dispy_20160614102701.dir:
“_群集”,(0,207) “计算1465918021755”,(512,85)
我无法猜测,除非我使用的是不稳定的版本。
发布于 2017-07-12 18:54:57
当第一次在网络上设置和使用dispy时,我发现在创建作业集群时必须指定客户端节点IP,请参见下面的内容:
cluster = dispy.JobCluster(compute, ip_addr=your_ip_address_here)看看这是否有帮助。
发布于 2016-06-14 18:55:43
如果您只是在客户端上运行sample.py,请在主语句中更改以下内容:
集群=dispy.JobCluster(计算,节点=‘nodeip_1’,'nodeip_2',…,‘nodeip_n’)
然后在IDE中或通过shell运行它。
我希望这能帮上忙。
发布于 2017-01-06 09:43:39
在执行python sample.py之前,dispynode.py仍然应该在本地主机或另一台机器上运行(如果您不想指定复杂的选项,请注意另一台机器应该在同一个网络中)。
我经历了同样的问题,并以这样的方式解决了这个问题:
$ dispynode.py (不要终止它)$ python sample.py不要忘记函数计算包含在等待一定的时间,输出应该在执行sample.py后至少20秒出现。
https://stackoverflow.com/questions/37817134
复制相似问题