Optimize websocket client queue

This commit is contained in:
tomkat83 2016-12-20 16:27:22 +01:00
parent ad8b7c7d90
commit 17fc11d8bb

View file

@ -2,9 +2,8 @@
###############################################################################
import logging
import json
from json import loads
import threading
import Queue
import websocket
import ssl
@ -36,7 +35,7 @@ class WebSocket(threading.Thread):
return False
try:
message = json.loads(message)
message = loads(message)
except Exception as ex:
log.error('Error decoding message from websocket: %s' % ex)
log.error(message)
@ -57,13 +56,8 @@ class WebSocket(threading.Thread):
return True
# Put PMS message on queue and let libsync take care of it
try:
self.queue.put(message)
return True
except Queue.Full:
# Queue only takes 200 messages. No worries if we miss one or two
log.info('Queue is full, dropping PMS message %s' % message)
return False
self.queue.put(message)
return True
def receive(self, ws):
# Not connected yet