我有一个Python脚本,我绑定了几个(例如5个)ZMQ接收器套接字,如下所示:
receiver_1 = context.socket(zmq.PULL)
receiver_1.bind("tcp://*:5555")
...
receiver_5 = context.socket(zmq.PULL)
receiver_5.bind("tcp://*:5559")
receivers = [receiver_1, ..., receiver_5]
然后我启动了一些Google Compute Engine实例,并连接相应的发件人套接字。
我想并行地从这些套接字中拉出来,所以我试图用多处理池来做这件事。代码看起来像这样:
def recv_result(i):
result_str = receivers[i].recv()
return cPickle.loads(result_str)
pool = multiprocessing.Pool()
while True:
results = pool.map(recv_result, [i for i in range(len(receivers))])
# break when all results have been received
...
我运行脚本时遇到的错误如下所示:
Traceback (most recent call last):
...
File ...
results = pool.map(recv_result, [i for i in range(len(receivers))])
File "/usr/lib/python2.7/multiprocessing/pool.py", line 227, in map
return self.map_async(func, iterable, chunksize).get()
File "/usr/lib/python2.7/multiprocessing/pool.py", line 528, in get
raise self._value
zmq.error.ZMQError: Interrupted system call
我也尝试使用multiprocessing.Process实现相同的功能,但我得到了基本相同的错误,但是以更混乱的方式。
我想要做的是更有效地接收我的GCE实例的所有结果,因为我发现这是我脚本中的瓶颈(在我目前的工作实现中,我只有一个接收器插槽,它连续地从所有GCE实例接收结果)。如果有人能指出我当前代码中的错误,或者有更好的方法来实现我的目标的任何建议,我将不胜感激!
答案 0 :(得分:3)
几点提示: