multiprocessing.Manager()。队列()。put错误

时间:2015-06-14 15:42:41

标签: python queue multiprocessing put

我正在使用python 2.6.4。我有一些代码可以获取一些数据,并将其放入队列中。过了一段时间,我开始从队列中提取数据。

q = multiprocessing.Manager().Queue()
p = multiprocessing.Process(target=build_queue, args=(q,))
# build_queue calls q.put and puts an object into queue. 
# The process of getting the objects to put into queue is slow.

# Later, I use asynchronous processes to pull data from the queue
pool = Pool(processes=4) 
for i in range(0, 4):
    pool.apply_async(pull_data_from_queue, (q))
    time.sleep(120)
pool.close()
# Wait for processes to finish
pool.join()

在操作过程中,程序退出并显示消息:“文件"(字符串)",第2行,放入”

如果我在q.put()周围放置一个try-except块并打印Exception,错误 - 打印消息是:  [Errno 32]破管

确切的错误是:

File "test.py", line 16, in build_queue
q.put(y)
File "<string>", line 2, in put
File "/opt/python/default-2.6/lib/python2.6/multiprocessing/managers.py", line 725, in _callmethod
conn.send((self._id, methodname, args, kwds))
IOError: [Errno 32] Broken pipe

任何想法为什么queue.put会抛出一条消息“File&#34;(string)&#34;,第2行,在put中”,我怎么能解决这个问题?

0 个答案:

没有答案