需要一些帮助!使用Rabbit MQ RPC运行python脚本时。我收到Socket 104
,Socket closed when connection was open
错误。下面是python traceback和一些代码:
Traceback (most recent call last):
File "./server.py", line 34, in <module>
channel.start_consuming()
File "/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py", line 1681, in start_consuming
self.connection.process_data_events(time_limit=None)
File "/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py", line 656, in process_data_events
self._dispatch_channel_events()
File "/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py", line 469, in _dispatch_channel_events
impl_channel._get_cookie()._dispatch_events()
File "/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py", line 1310, in _dispatch_events
evt.body)
File "./server.py", line 30, in on_request
body=json.dumps(DEVICE_INFO))
File "/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py", line 1978, in basic_publish
mandatory, immediate)
File "/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py", line 2065, in publish
self._flush_output()
File "/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py", line 1174, in _flush_output
*waiters)
File "/usr/lib/python2.6/site-packages/pika/adapters/blocking_connection.py", line 395, in _flush_output
raise exceptions.ConnectionClosed()
pika.exceptions.ConnectionClosed
答案 0 :(得分:0)
可能是由于与rabbitmq服务器失去连接,因为pika没有处理断开连接,并且经常导致类似的堆栈跟踪。
我也有类似的问题,在我的情况下,这是因为我的鼠兔连接在一段时间后才开始下降,我的同事能够通过为mq:port_number
添加等待时间来处理这个问题。
我们使用的是docker容器,所以我们在invoke.sh中添加了以下行来等待mq:
filename.py --wait-secs 30 --port-wait mq:5672
我希望你能做到这一点后解决这个问题。
否则最好在python脚本运行之前检查pika是否正在删除连接,或者提供有关如何调用它的更多信息。