如何解决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 使用所有集群资源运行我的函数吗?
非常感谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。