ignore messages that can not be serialized

This commit is contained in:
j 2015-05-19 02:39:26 +05:30
parent af86445b2e
commit 47a3a24a7d

View file

@ -62,14 +62,22 @@ class Handler(WebSocketHandler):
#logger.debug('got message %s', message) #logger.debug('got message %s', message)
def post(self, event, data): def post(self, event, data):
message = json.dumps([event, data]) try:
message = json.dumps([event, data])
except:
logger.debug('failed to serialize data %s %s', event, data)
return
main = IOLoop.instance() main = IOLoop.instance()
main.add_callback(lambda: self.write_message(message)) main.add_callback(lambda: self.write_message(message))
def trigger_event(event, data): def trigger_event(event, data):
logger.debug('trigger event %s %s to %s clients', event, data, len(sockets)) logger.debug('trigger event %s %s to %s clients', event, data, len(sockets))
main = IOLoop.instance() main = IOLoop.instance()
message = json.dumps([event, data]) try:
message = json.dumps([event, data])
except:
logger.debug('faild to serialise data')
return
for ws in sockets: for ws in sockets:
try: try:
main.add_callback(lambda: ws.write_message(message)) main.add_callback(lambda: ws.write_message(message))