Optimize some websocket code

This commit is contained in:
croneter 2020-05-07 07:48:50 +02:00
parent 54a147da41
commit 5ffcd5782d
4 changed files with 24 additions and 18 deletions

View file

@ -22,7 +22,7 @@ class App(object):
if entrypoint:
self.load_entrypoint()
else:
self.load()
self.reload()
# Quit PKC?
self.stop_pkc = False
# This will suspend the main thread also
@ -160,7 +160,7 @@ class App(object):
if xbmc.sleep(100):
return True
def load(self):
def reload(self):
# Number of items to fetch and display in widgets
self.fetch_pms_item_number = int(utils.settings('fetch_pms_item_number'))
# Hack to force Kodi widget for "in progress" to show up if it was empty

View file

@ -80,6 +80,7 @@ class Sync(object):
# List of section_ids we're synching to Kodi - will be automatically
# re-built if sections are set a-new
self.section_ids = set()
self.enable_alexa = None
self.load()
@ -113,11 +114,18 @@ class Sync(object):
self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true'
self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true'
self.sync_specific_kodi_playlists = utils.settings('syncSpecificKodiPlaylists') == 'true'
self.sync_dialog = utils.settings('dbSyncIndicator') == 'true'
self.full_sync_intervall = int(utils.settings('fullSyncInterval')) * 60
self.background_sync_disabled = utils.settings('enableBackgroundSync') == 'false'
self.backgroundsync_saftymargin = int(utils.settings('backgroundsync_saftyMargin'))
self.sync_thread_number = int(utils.settings('syncThreadNumber'))
self.reload()
def reload(self):
"""
Any settings unrelated to syncs to the Kodi database - can thus be
safely reset without a Kodi reboot
"""
self.background_sync_disabled = utils.settings('enableBackgroundSync') == 'false'
self.enable_alexa = utils.settings('enable_alexa') == 'true'
self.sync_dialog = utils.settings('dbSyncIndicator') == 'true'
self.full_sync_intervall = int(utils.settings('fullSyncInterval')) * 60
self.backgroundsync_saftymargin = int(utils.settings('backgroundsync_saftyMargin'))
self.image_sync_notifications = utils.settings('imageSyncNotifications') == 'true'

View file

@ -535,8 +535,7 @@ class Service(object):
self.sync.start()
self.plexcompanion.start()
self.playqueue.start()
if utils.settings('enable_alexa') == 'true':
self.alexa.start()
self.alexa.start()
xbmc.sleep(100)

View file

@ -22,6 +22,11 @@ class WebSocket(backgroundthread.KillableThread):
self.sleeptime = 0.0
super(WebSocket, self).__init__()
def close_websocket(self):
if self.ws is not None:
self.ws.close()
self.ws = None
def process(self, opcode, message):
raise NotImplementedError
@ -62,9 +67,7 @@ class WebSocket(backgroundthread.KillableThread):
try:
self._run()
finally:
# Close websocket connection on shutdown
if self.ws is not None:
self.ws.close()
self.close_websocket()
app.APP.deregister_thread(self)
LOG.info("##===---- %s Stopped ----===##", self.__class__.__name__)
@ -73,9 +76,7 @@ class WebSocket(backgroundthread.KillableThread):
# In the event the server goes offline
if self.should_suspend():
# Set in service.py
if self.ws is not None:
self.ws.close()
self.ws = None
self.close_websocket()
if self.wait_while_suspended():
# Abort was requested while waiting. We should exit
return
@ -132,9 +133,7 @@ class WebSocket(backgroundthread.KillableThread):
import traceback
LOG.error("%s: Traceback:\n%s",
self.__class__.__name__, traceback.format_exc())
if self.ws is not None:
self.ws.close()
self.ws = None
self.close_websocket()
class PMS_Websocket(WebSocket):