Python 2.6 send connection object over Queue / Pipe / etc(Python 2.6 通过队列/管道/等发送连接对象)
问题描述
鉴于 此错误(Python 问题 4892) 会导致以下错误:
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
有人知道在队列上传递 Connection 对象的解决方法吗?
Does anyone know of a workaround to pass a Connection object on a Queue?
谢谢.
推荐答案
(我相信是)一个更好的方法,经过一些玩弄(我遇到了同样的问题.想通过管道穿过管道.)之前发现这篇文章:
(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:
>>> from multiprocessing import Pipe, reduction
>>> i, o = Pipe()
>>> reduced = reduction.reduce_connection(i)
>>> newi = reduced[0](*reduced[1])
>>> newi.send("hi")
>>> o.recv()
'hi'
我不完全确定为什么要以这种方式构建(有人需要深入了解多处理的减少部分到底是什么),但它确实有效,并且不需要导入泡菜.除此之外,它的功能与上述非常接近,但更简单.我还把它扔进了 python 错误报告,以便其他人知道解决方法.
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.
这篇关于Python 2.6 通过队列/管道/等发送连接对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Python 2.6 通过队列/管道/等发送连接对象


基础教程推荐
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 筛选NumPy数组 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01