Commit 13bd0ea3 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added the ability to give directly a callable object to the on_disconnect callback.

parent f9c01b08
......@@ -320,22 +320,32 @@ class RpcConnection(object):
else:
pass # Malformed messages are note processed
def shutdown(self, callback_name=None):
def shutdown(self, callback=None):
'''
Shutdown this connection.
:param callback_name: Name of the callback to call on the handler
:type callback_name: :class:`str` or None
:param callback: Name of the callback to call on the handler or a
callable to call when the connection is shutdown.
:type callback: :class:`str` or callable or None
'''
self._sock.close()
if callback_name is not None and self._handler is not None:
try:
func = self._handler[callback_name]
except KeyError:
pass
if callback is not None and not callable(callback):
if self._handler is not None:
try:
callback = self._handler[callback]
except KeyError:
callback = None
else:
func(self)
callback = None
if callback is not None:
try:
callback(self)
except Exception as err:
logging.error('Error while execution of shutdown '
'callback: %s' % err)
def clean_call(self, msg_id):
'''
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment