From 793bd665541c81a994c998d364d604bc6efbbdd8 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Fri, 22 Jul 2016 17:10:35 -0500 Subject: [PATCH] Fix crash when sleeping/waking up device --- resources/lib/downloadutils.py | 1 + resources/lib/kodimonitor.py | 5 +++++ resources/lib/userclient.py | 6 +++--- service.py | 17 ++++++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 34596c2f..ac8bd9ab 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -289,6 +289,7 @@ class DownloadUtils(): log("Unable to convert the response for: %s" % url, 1) else: # Bad status code + log("=== Bad status response: %s ===" % r.status_code, -1) r.raise_for_status() ##### EXCEPTIONS ##### diff --git a/resources/lib/kodimonitor.py b/resources/lib/kodimonitor.py index 16baa487..6ba9e76d 100644 --- a/resources/lib/kodimonitor.py +++ b/resources/lib/kodimonitor.py @@ -195,10 +195,15 @@ class KodiMonitor(xbmc.Monitor): finally: embycursor.close()''' + elif method == "System.OnSleep": + # Connection is going to sleep + log("Marking the server as offline. System.OnSleep activating.", 1) + window('emby_online', value="sleep") elif method == "System.OnWake": # Allow network to wake up xbmc.sleep(10000) + window('emby_online', value="false") window('emby_onWake', value="true") diff --git a/resources/lib/userclient.py b/resources/lib/userclient.py index d08e00ae..60cb5456 100644 --- a/resources/lib/userclient.py +++ b/resources/lib/userclient.py @@ -23,7 +23,7 @@ class UserClient(threading.Thread): # Borg - multiple instances, shared state _shared_state = {} - stopClient = False + stop_thread = False auth = True retry = 0 @@ -430,7 +430,7 @@ class UserClient(threading.Thread): self.auth = True - if self.stopClient == True: + if self.stop_thread == True: # If stopping the client didn't work break @@ -443,4 +443,4 @@ class UserClient(threading.Thread): def stopClient(self): # When emby for kodi terminates - self.stopClient = True \ No newline at end of file + self.stop_thread = True \ No newline at end of file diff --git a/service.py b/service.py index 9d79adfd..13a9d1f0 100644 --- a/service.py +++ b/service.py @@ -231,7 +231,21 @@ class Service(): sound=False) self.server_online = False - + + elif window('emby_online') == "sleep": + # device going to sleep + if self.websocket_running: + log("Stop websocket thread") + ws.stopClient() + ws = wsc.WebSocket_Client() + self.websocket_running = False + + if self.library_running: + log("Stop library thread") + library.stopThread() + library = librarysync.LibrarySync() + self.library_running = False + else: # Server is online if not self.server_online: @@ -254,6 +268,7 @@ class Service(): # Start the userclient thread if not self.userclient_running: + log("Start user thread") self.userclient_running = True user.start()