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 (将#修改为@)