Python中的并发轮询问题
这个问题已经困扰我好几天了。通过打开多个线程,我正在使用RabbitMQ运行多个使用者,我得到以下错误Python中的并发轮询问题,python,rabbitmq,Python,Rabbitmq,这个问题已经困扰我好几天了。通过打开多个线程,我正在使用RabbitMQ运行多个使用者,我得到以下错误 File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 905, in queue_declare None, replies) File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blockin
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 905, in queue_declare
None, replies)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 1141, in _rpc
self._wait_on_response(method_frame))
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 1162, in _send_method
self.connection.process_data_events()
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 240, in process_data_events
if self._handle_read():
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 347, in _handle_read
if self._read_poller.ready():
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 43, in inner
return f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pika/adapters/blocking_connection.py", line 85, in ready
events = self.poller.poll(self.poll_timeout)
RuntimeError: concurrent poll() invocation
通过大量的谷歌搜索,我找到了一个描述如何不能并发调用select.poll()函数的方法。
以下脚本可以始终如一地触发此错误:
import os
import select
import threading
import time
p = select.poll()
rfds = []
r, w = os.pipe()
for i in range(1000):
fd = os.dup(r)
rfds.append(fd)
p.register(fd, select.POLLIN)
def resize_ufds_array():
time.sleep(0.5)
# trigger ufds array reallocation
for fd in rfds:
p.unregister(fd)
p.register(w, select.POLLOUT)
p.poll()
# and make the call to poll() from the main thread return
os.write(w, b'hello')
t = threading.Thread(target=resize_ufds_array)
t.start()
p.poll()
我发现这个脚本无法触发从WindowsMSI安装的本地Python 2.7.8上的错误,因为select.poll已被删除。然而,在我的prod环境中,它是Ubuntu14.04,我尝试从源代码安装Python2.7.6-2.7.9,它们都有这个bug。你知道如何在Ubuntu上解决这个问题吗?对于2.7版本的这个问题,有一个python修复程序,但是在我应用补丁后,脚本仍然显示错误