worker.py 文件源码

python
阅读 39 收藏 0 点赞 0 评论 0

项目:research-dist 作者: DrawML 项目源码 文件源码
def worker_thread(_url, context, i):
    master = context.socket(zmq.REQ)
    master.identity = ("Worker-%d" % i).encode('ascii')
    master.connect(_url)

    # [performance, status]
    master.send_multipart([i.to_bytes(1, 'little'), b"", b'READY'])
    print("[%s] I'm ready..." % (master.identity.decode('ascii')))

    while True:
        [client_addr, empty, request] = master.recv_multipart()
        assert empty == b""

        print("[%s] Processing task... %s / %s" % (master.identity.decode('ascii'),
                                                    client_addr.decode('ascii'),
                                                    request.decode('ascii')))

        time.sleep(randrange(1, 10))

        print("[%s] finish task... %s / %s" % (master.identity.decode('ascii'),
                                                    client_addr.decode('ascii'),
                                                    request.decode('ascii')))

        master.send_multipart([i.to_bytes(1, 'little'), b"", client_addr, b"", b"FINISH"])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号