Python 2.6 通过队列/管道/等发送连接对象
鉴于 此错误(Python 问题 4892) 会导致以下错误:
>>> import multiprocessing
>>> multiprocessing.allow_connection_pickling()
>>> q = multiprocessing.Queue()
>>> p = multiprocessing.Pipe()
>>> q.put(p)
>>> q.get()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../python2.6/multiprocessing/queues.py", line 91, in get
res = self._recv()
TypeError: Required argument 'handle' (pos 1) not found
有谁知道解决方法在队列上传递连接对象?
谢谢。
Given this bug (Python Issue 4892) that gives rise to the following error:
>>> import multiprocessing
>>> multiprocessing.allow_connection_pickling()
>>> q = multiprocessing.Queue()
>>> p = multiprocessing.Pipe()
>>> q.put(p)
>>> q.get()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/.../python2.6/multiprocessing/queues.py", line 91, in get
res = self._recv()
TypeError: Required argument 'handle' (pos 1) not found
Does anyone know of a workaround to pass a Connection object on a Queue?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
(我相信的是)在发现这篇文章之前,经过一番尝试(我遇到了同样的问题。想要通过管道穿过管道。)这是一个更好的方法:
我不完全确定为什么要这样构建(有人需要深入了解多处理的减少部分到底是什么),但它确实有效,并且不需要 pickle 导入。除此之外,它的功能与上面的非常接近,但更简单。我还将其放入 python 错误报告中,以便其他人知道解决方法。
(What I believe is) A better method, after some playing around (I was having the same problem. Wanted to pass a pipe through a pipe.) before discovering this post:
I'm not entirely sure why this is built this way (someone would need insight into what the heck the reduction part of multiprocessing is about for that) but it does definitely work, and requires no pickle import. Other than that, it's pretty close to the above in what it does, but simpler. I also threw this into the python bug report so others know of the workaround.
这大致是我所做的:
最后
一行是神秘的,来自以下内容:
希望对其他人有帮助。它对我来说效果很好。
Here's roughly what I did:
and
The last line is cryptic, coming from the following:
Hope that helps someone else. It works fine for me.