Optimize some websocket code
This commit is contained in:
parent
54a147da41
commit
5ffcd5782d
4 changed files with 24 additions and 18 deletions
|
@ -22,7 +22,7 @@ class App(object):
|
||||||
if entrypoint:
|
if entrypoint:
|
||||||
self.load_entrypoint()
|
self.load_entrypoint()
|
||||||
else:
|
else:
|
||||||
self.load()
|
self.reload()
|
||||||
# Quit PKC?
|
# Quit PKC?
|
||||||
self.stop_pkc = False
|
self.stop_pkc = False
|
||||||
# This will suspend the main thread also
|
# This will suspend the main thread also
|
||||||
|
@ -160,7 +160,7 @@ class App(object):
|
||||||
if xbmc.sleep(100):
|
if xbmc.sleep(100):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def load(self):
|
def reload(self):
|
||||||
# Number of items to fetch and display in widgets
|
# Number of items to fetch and display in widgets
|
||||||
self.fetch_pms_item_number = int(utils.settings('fetch_pms_item_number'))
|
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
|
# Hack to force Kodi widget for "in progress" to show up if it was empty
|
||||||
|
|
|
@ -80,6 +80,7 @@ class Sync(object):
|
||||||
# List of section_ids we're synching to Kodi - will be automatically
|
# List of section_ids we're synching to Kodi - will be automatically
|
||||||
# re-built if sections are set a-new
|
# re-built if sections are set a-new
|
||||||
self.section_ids = set()
|
self.section_ids = set()
|
||||||
|
self.enable_alexa = None
|
||||||
|
|
||||||
self.load()
|
self.load()
|
||||||
|
|
||||||
|
@ -113,11 +114,18 @@ class Sync(object):
|
||||||
self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true'
|
self.show_extras_instead_of_playing_trailer = utils.settings('showExtrasInsteadOfTrailer') == 'true'
|
||||||
self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true'
|
self.sync_specific_plex_playlists = utils.settings('syncSpecificPlexPlaylists') == 'true'
|
||||||
self.sync_specific_kodi_playlists = utils.settings('syncSpecificKodiPlaylists') == '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.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'
|
self.image_sync_notifications = utils.settings('imageSyncNotifications') == 'true'
|
||||||
|
|
|
@ -535,8 +535,7 @@ class Service(object):
|
||||||
self.sync.start()
|
self.sync.start()
|
||||||
self.plexcompanion.start()
|
self.plexcompanion.start()
|
||||||
self.playqueue.start()
|
self.playqueue.start()
|
||||||
if utils.settings('enable_alexa') == 'true':
|
self.alexa.start()
|
||||||
self.alexa.start()
|
|
||||||
|
|
||||||
xbmc.sleep(100)
|
xbmc.sleep(100)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,11 @@ class WebSocket(backgroundthread.KillableThread):
|
||||||
self.sleeptime = 0.0
|
self.sleeptime = 0.0
|
||||||
super(WebSocket, self).__init__()
|
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):
|
def process(self, opcode, message):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -62,9 +67,7 @@ class WebSocket(backgroundthread.KillableThread):
|
||||||
try:
|
try:
|
||||||
self._run()
|
self._run()
|
||||||
finally:
|
finally:
|
||||||
# Close websocket connection on shutdown
|
self.close_websocket()
|
||||||
if self.ws is not None:
|
|
||||||
self.ws.close()
|
|
||||||
app.APP.deregister_thread(self)
|
app.APP.deregister_thread(self)
|
||||||
LOG.info("##===---- %s Stopped ----===##", self.__class__.__name__)
|
LOG.info("##===---- %s Stopped ----===##", self.__class__.__name__)
|
||||||
|
|
||||||
|
@ -73,9 +76,7 @@ class WebSocket(backgroundthread.KillableThread):
|
||||||
# In the event the server goes offline
|
# In the event the server goes offline
|
||||||
if self.should_suspend():
|
if self.should_suspend():
|
||||||
# Set in service.py
|
# Set in service.py
|
||||||
if self.ws is not None:
|
self.close_websocket()
|
||||||
self.ws.close()
|
|
||||||
self.ws = None
|
|
||||||
if self.wait_while_suspended():
|
if self.wait_while_suspended():
|
||||||
# Abort was requested while waiting. We should exit
|
# Abort was requested while waiting. We should exit
|
||||||
return
|
return
|
||||||
|
@ -132,9 +133,7 @@ class WebSocket(backgroundthread.KillableThread):
|
||||||
import traceback
|
import traceback
|
||||||
LOG.error("%s: Traceback:\n%s",
|
LOG.error("%s: Traceback:\n%s",
|
||||||
self.__class__.__name__, traceback.format_exc())
|
self.__class__.__name__, traceback.format_exc())
|
||||||
if self.ws is not None:
|
self.close_websocket()
|
||||||
self.ws.close()
|
|
||||||
self.ws = None
|
|
||||||
|
|
||||||
|
|
||||||
class PMS_Websocket(WebSocket):
|
class PMS_Websocket(WebSocket):
|
||||||
|
|
Loading…
Reference in a new issue