Python Distributed Computing (works)

时光怂恿深爱的人放手 提交于 2019-12-05 04:31:56

ValueError: insecure string pickle is raised when your pickle is corrupted. Are you sure you are receiving the entire pickled object in one sock.recv() (unpack.py)?

Edit: to avoid this for any size you could do (your Socket class would have to support recv to be called with an buffer size argument (i.e

 class Socket:
    def recv(self, bufsize):
        return self.sock.recv(bufsize)

)):

import struct

struct.pack('Q', len(pickled_list))
# Send it, and then send the pickled list.

In the receiver program:

import struct

length = struct.unpack('Q', sock.recv(struct.calcsize('Q')))[0]
pickled_list = sock.recv(length)

'Q' is an unsigned long long. For other struct things see the struct module documentation

I don't think Process objects are designed to be sent over the network. Look at line 256 in multiprocessing/process.py.

# We subclass bytes to avoid accidental transmission of auth keys over network.

Sounds like there's a good reason to me. If you want to do distributed computing, maybe you should look into a library designed for that.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!