python - python dispy 无法将我的函数分布在节点上
问题描述
我是 python dispy 的新手,我正在尝试执行计算测试函数以在我的集群节点上进行性能测量。我在我的客户上写了这个:
from time import monotonic
from hashlib import sha256
import socket
# Mine local test
def mine(message, difficulty=1):
assert difficulty >= 1
prefix = '1' * difficulty
hosts = []
for i in range(10000000):
digest = sha256(str(hash(message+ str(i))).encode('utf-8'))
if digest.hexdigest().startswith(prefix):
print ("after " + str(i) + " iterations found nonce: "+ digest.hexdigest())
hosts.append(socket.gethostname())
return hosts
if __name__ == '__main__':
import dispy, random, socket
# fetch the IP address of the client
start_t = monotonic()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80)) # doesn't matter if 8.8.8.8 can't be reached
cluster = dispy.JobCluster(mine,ip_addr="172.16.1.20", nodes="172.16.1.*")
jobs = []
job = cluster.submit("Test text",4)
jobs.append(job)
for job in jobs:
print("Preparing for starting job ", job)
host = job() # waits for job to finish and returns results
stop_t = monotonic()
print('executed job %s at %s' % (host, (stop_t-start_t)))
cluster.print_status()
cluster.close()
但是当我使用 python3 compute.py 运行时,我得到了
在 0.11133299399989482 处执行的作业无
我的函数无法执行并报告说使用单个节点而不是集群中的所有节点,有人可以帮助我使用 python dispy 使用所有集群资源运行我的函数吗?
非常感谢
解决方案
推荐阅读
- c# - Outlook 的电子邮件类型为 EX 时如何获取发件人的电子邮件?
- entity-framework - 您的启动项目“项目”未引用 Microsoft.EntityFrameworkCore.Design
- pentaho - 在 Pentaho Server 8 CE 中写入本地文件系统
- python-3.x - 如何调整散景热图的宽度并去除周围的空白
- django - 即使在编译消息后,翻译也不能在 Django 1.5 中工作
- git - Is the time taken to git commit dependent on file size? Also, how much time does it take to restore a previous version in git?
- azure-devops - 为什么这些 Azure DevOps 预定义变量在管道构建中不起作用?
- php - 通过 PHP 从另一台服务器运行 python 脚本
- python - 在文件python中返回行的总和或差异时遇到问题
- android - 如何使用颤振本地化启动器中显示的应用程序名称?