- show error log if a error occurs.
This commit is contained in:
liris
2013-07-30 14:52:54 +09:00
parent 38cb5a8e15
commit 56cd3361db

View File

@@ -779,7 +779,7 @@ class WebSocketApp(object):
try: try:
self.sock = WebSocket(self.get_mask_key, sockopt=sockopt, sslopt=sslopt) self.sock = WebSocket(self.get_mask_key, sockopt=sockopt, sslopt=sslopt)
self.sock.connect(self.url, header=self.header) self.sock.connect(self.url, header=self.header)
self._run_with_no_err(self.on_open) self._callback(self.on_open)
if ping_interval: if ping_interval:
thread = threading.Thread(target=self._send_ping, args=(ping_interval,)) thread = threading.Thread(target=self._send_ping, args=(ping_interval,))
@@ -790,23 +790,22 @@ class WebSocketApp(object):
data = self.sock.recv() data = self.sock.recv()
if data is None: if data is None:
break break
self._run_with_no_err(self.on_message, data) self._callback(self.on_message, data)
except Exception, e: except Exception, e:
self._run_with_no_err(self.on_error, e) self._callback(self.on_error, e)
finally: finally:
if thread: if thread:
thread.join() thread.join()
self.sock.close() self.sock.close()
self._run_with_no_err(self.on_close) self._callback(self.on_close)
self.sock = None self.sock = None
def _run_with_no_err(self, callback, *args): def _callback(self, callback, *args):
if callback: if callback:
try: try:
callback(self, *args) callback(self, *args)
except Exception, e: except Exception, e:
if logger.isEnabledFor(logging.DEBUG): logger.error(e)
logger.error(e)
if __name__ == "__main__": if __name__ == "__main__":