Nyxynyx
Nyxynyx

Reputation: 63619

Using pika connection.close() gives "WARNING:pika.adapters.base_connection:Unknown state on disconnect: 0"

When closing a connection to RabbitMQ server using pika, the warning WARNING:pika.adapters.base_connection:Unknown state on disconnect: 0 appears.

If no connection.close() is used, the warning does not appear. What is causing this warning, and is this something we can ignore?

Using Python 2.7, RabbitMQ 3.2.2, iPython 1.1.0, pika 0.9.13 on Mac OSX.

enter image description here

Upvotes: 3

Views: 5346

Answers (2)

Mukul M.
Mukul M.

Reputation: 541

This happens to me in RabbitMQ 3.3.3 if I close my BlockingConnection before the channel is completely closed. The solution is to close your connection in the close-callback of the channel. Also, use a context manager to automatically close the channel.

params = pika.ConnectionParameters(host=self._host, port=self._port)
connection = pika.BlockingConnection(params)
with contextlib.closing(connection.channel()) as channel:
    # Close connection once channel is closed
    def closeConnection(channel, replyCode, replyText):
        connection.close()
    channel.add_on_close_callback(closeConnection)

    # Declare a durable queue; we will use the default exchange for
    # simple key-based routing
    channel.queue_declare(queue=self._queueName, durable=True) 
    ...
    ...

Upvotes: 0

This was fixed with pull request #346. Just wait for a new version :)

Upvotes: 2

Related Questions