wcooley / ragve

Automatically exported from code.google.com/p/ragve
0 stars 0 forks source link

Pika cannot handle tcpkill command. 'NoneType' is not catched in Pika library - particularly in File "/usr/local/lib/python2.7/dist-packages/pika-0.9.5-py2.7.egg/pika/adapters/base_connection.py", in function "def _handle_error(self, error):" #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Use this command to cut the TCP connection between client and amqp server.
sudo tcpkill -i wlan0 port 59556

Result:

Traceback (most recent call last):
  File "D2LAgent.py", line 464, in <module>
    fetch_job(d2l_agent)
  File "/home/locngo/workspace/ragve/branches/TRY-DVG-puka/lib/python/mq/d2lAgentConsume.py", line 108, in fetch_job
    connection.ioloop.start()
  File "/usr/local/lib/python2.7/dist-packages/pika-0.9.5-py2.7.egg/pika/adapters/select_connection.py", line 125, in start
    self.poller.start()
  File "/usr/local/lib/python2.7/dist-packages/pika-0.9.5-py2.7.egg/pika/adapters/select_connection.py", line 378, in start
    self.poll()
  File "/usr/local/lib/python2.7/dist-packages/pika-0.9.5-py2.7.egg/pika/adapters/select_connection.py", line 397, in poll
    self._handler(events[0][0], events[0][1])
  File "/usr/local/lib/python2.7/dist-packages/pika-0.9.5-py2.7.egg/pika/adapters/base_connection.py", line 143, in _handle_events
    self._handle_error(error)
  File "/usr/local/lib/python2.7/dist-packages/pika-0.9.5-py2.7.egg/pika/adapters/base_connection.py", line 108, in _handle_error
    error_code = error[0]  # Python <= 2.5
TypeError: 'NoneType' object is not subscriptable

The receiver's thread stops unexpectedly.

Original issue reported on code.google.com by lockon...@gmail.com on 9 Feb 2012 at 11:45

GoogleCodeExporter commented 9 years ago
Add a patch for d2lAgentConsume.py to handle TypeError exception.

def rough_connect(parameters,on_connected,srs):
    connection = SelectConnection(parameters, on_open_callback=on_connected, reconnection_strategy=srs)
    try:
        # Loop so we can communicate with RabbitMQ
        connection.ioloop.start()
    except KeyboardInterrupt:
        # Gracefully close the connection
        connection.close()
        # Loop until we're fully closed, will stop on its own
        connection.ioloop.start()
    except Exception as inst:
        print "Encounter exception " + str(inst) + " create another connection"
        rough_connect(parameters,on_connected,srs)

def fetch_job(d2l_agent):
    global agent
    agent = d2l_agent
    agent.log.info('post_job(): MQ Parameter setup')
    credentials = pika.PlainCredentials( agent.mq_username, agent.mq_password)

    parameters = pika.ConnectionParameters(
        host = agent.mq_hostname,
        credentials = credentials,
        virtual_host = agent.mq_vhost)
        #heartbeat = True

    agent.log.info('post_job(): Setting-up connection, host: ' + agent.mq_hostname )

    # Step #1: Connect to RabbitMQ
    srs = SimpleReconnectionStrategy()
    rough_connect(parameters,on_connected,srs)

Original comment by lockon...@gmail.com on 10 Feb 2012 at 11:27