pika/pika — Issue #95: channel.add_on_close_callback callback called with unexpected parameters
Author: alanxz
Created: 2011-10-17 16:31:11+00:00
State: open

The callback specified with channel.add_on_close_callback gets called with unexpected parameters. With the documentation http://pika.github.com/communicating.html#blocking_connection.BlockingChannel.add_on_close_callback I would expect one parameter of the frame type, with a Channel.Close type for the method field of that frame object. What gets passed back is *args, and **keywords

Relevant example code:

def _handle_close(method_frame):
if (method_frame.reply_code != 200 and
method_frame.class_id == 60 and
method_frame.method_id == 40) :
raise RuntimeError("Basic.Publish caused a Channel.Close: " + method_frame.reply_text + " (is service running?)")
else :
raise RuntimeError("Channel.Close while waiting for RPC response")

channel.basic_consume(_handle_delivery, queue=declare_ok.method.queue)

channel.add_on_close_callback(_handle_close)

properties=pika.BasicProperties(reply_to="ReplyToRoutingKey")

# Publish to a non-existant exchange to raise a channel error
channel.basic_publish(exchange='IDontExist,
routing_key='RoutingKey',
body='The message',
properties=properties,
mandatory=True)

channel.start_consuming()

The traceback I get as a result:
```
Traceback (most recent call last):
<<<....snip....>>>>
File "D:\dev\python_amqp_rpc\amqp_rpc_proxy.py", line 127, in amqp_rpc_proxy
channel.start_consuming()
File "C:\Python27\lib\site-packages\pika\adapters\blocking_connection.py", line 293, in start_consuming
self.transport.connection.process_data_events()
File "C:\Python27\lib\site-packages\pika\adapters\blocking_connection.py", line 94, in process_data_events
self._handle_read()
File "C:\Python27\lib\site-packages\pika\adapters\base_connection.py", line 162, in _handle_read
self._on_data_available(data)
File "C:\Python27\lib\site-packages\pika\connection.py", line 589, in _on_data_available
frame) # Args
File "C:\Python27\lib\site-packages\pika\callback.py", line 124, in process
callback(*args, **keywords)
File "C:\Python27\lib\site-packages\pika\adapters\blocking_connection.py", line 267, in _on_remote_close
Channel._on_remote_close(self, frame)
File "C:\Python27\lib\site-packages\pika\channel.py", line 301, in _on_remote_close
frame.method.reply_text)
File "C:\Python27\lib\site-packages\pika\callback.py", line 124, in process
callback(*args, **keywords)
TypeError: _handle_close() takes exactly 1 argument (2 given)
```