pika/pika — Issue #104: Connection.is_open always returns True
Author: dsuch
Created: 2011-11-11 17:17:29+00:00
State: open

Hi,

below is a piece of code I've written to test out the new reconnection-related goodies but at the current tip (61fcd644e6) the call to Connection.is_open always returns True, that is, the Connection's connection_state is always CONNECTION_OPEN even if I recycle the RabbitMQ broker in between the calls to channel.basic_publish (stop it, wait 2 minutes and start it up again). I was expecting it to become CONNECTION_CLOSED or anything that would make .is_open return False.

```python
# stdlib
import time

# Pika
from pika import log
from pika.adapters import SelectConnection
from pika.connection import ConnectionParameters

log.setup(log.INFO)

class ReconnectionRunner(object):
def __init__(self):
self.host = '127.0.0.1'
self.virtual_host = '/'
self.exchange = 'amq.direct'
self.routing_key = b''

self.conn_params = ConnectionParameters(self.host, virtual_host=self.virtual_host, connection_attempts=None)

def run(self):
self.conn = SelectConnection(self.conn_params, self.on_connected)

try:
self.conn.ioloop.start()
except KeyboardInterrupt:
self.conn.close()

def on_connected(self, conn):
self.conn.channel(self.on_channel_open)

def on_channel_open(self, channel):
for x in xrange(0, 100000):
message = "Hello World #%i: %.8f" % (x, time.time())
if self.conn.is_open:
channel.basic_publish(self.exchange, self.routing_key, message)

log.info(message)
time.sleep(1)
else:
log.info('Connection is closed')

if __name__ == '__main__':
ReconnectionRunner().run()
```