Rename thread methods

This commit is contained in:
croneter 2018-02-11 14:57:39 +01:00
parent 5068327408
commit e02e9bcd1f
13 changed files with 82 additions and 83 deletions

View File

@ -221,8 +221,8 @@ class PlexCompanion(Thread):
httpd = self.httpd
# Cache for quicker while loops
client = self.client
thread_stopped = self.thread_stopped
thread_suspended = self.thread_suspended
stopped = self.stopped
suspended = self.suspended
# Start up instances
request_mgr = httppersist.RequestMgr()
@ -259,12 +259,12 @@ class PlexCompanion(Thread):
if httpd:
thread = Thread(target=httpd.handle_request)
while not thread_stopped():
while not stopped():
# If we are not authorized, sleep
# Otherwise, we trigger a download which leads to a
# re-authorizations
while thread_suspended():
if thread_stopped():
while suspended():
if stopped():
break
sleep(1000)
try:

View File

@ -50,15 +50,15 @@ class Image_Cache_Thread(Thread):
Thread.__init__(self)
def run(self):
thread_stopped = self.thread_stopped
thread_suspended = self.thread_suspended
stopped = self.stopped
suspended = self.suspended
queue = self.queue
sleep_between = self.sleep_between
while not thread_stopped():
while not stopped():
# In the event the server goes offline
while thread_suspended():
while suspended():
# Set in service.py
if thread_stopped():
if stopped():
# Abort was requested while waiting. We should exit
LOG.info("---===### Stopped Image_Cache_Thread ###===---")
return
@ -84,7 +84,7 @@ class Image_Cache_Thread(Thread):
# download. All is well
break
except requests.ConnectionError:
if thread_stopped():
if stopped():
# Kodi terminated
break
# Server thinks its a DOS attack, ('error 10053')

View File

@ -22,10 +22,10 @@ class Monitor_Window(Thread):
Adjusts state.py accordingly
"""
def run(self):
thread_stopped = self.thread_stopped
stopped = self.stopped
queue = state.COMMAND_PIPELINE_QUEUE
LOG.info("----===## Starting Kodi_Play_Client ##===----")
while not thread_stopped():
while not stopped():
if window('plex_command'):
value = window('plex_command')
window('plex_command', clear=True)

View File

@ -400,7 +400,7 @@ class SpecialMonitor(Thread):
LOG.info("----====# Starting Special Monitor #====----")
# "Start from beginning", "Play from beginning"
strings = (getLocalizedString(12021), getLocalizedString(12023))
while not self.thread_stopped():
while not self.stopped():
if (getCondVisibility('Window.IsVisible(DialogContextMenu.xml)') and
getInfoLabel('Control.GetLabel(1002)') in strings):
# Remember that the item IS indeed resumable

View File

@ -54,14 +54,14 @@ class Process_Fanart_Thread(Thread):
Do the work
"""
log.debug("---===### Starting FanartSync ###===---")
thread_stopped = self.thread_stopped
thread_suspended = self.thread_suspended
stopped = self.stopped
suspended = self.suspended
queue = self.queue
while not thread_stopped():
while not stopped():
# In the event the server goes offline
while thread_suspended():
while suspended():
# Set in service.py
if thread_stopped():
if stopped():
# Abort was requested while waiting. We should exit
log.info("---===### Stopped FanartSync ###===---")
return

View File

@ -47,7 +47,7 @@ class Threaded_Get_Metadata(Thread):
continue
else:
self.queue.task_done()
if self.thread_stopped():
if self.stopped():
# Shutdown from outside requested; purge out_queue as well
while not self.out_queue.empty():
# Still try because remaining item might have been taken
@ -78,8 +78,8 @@ class Threaded_Get_Metadata(Thread):
# cache local variables because it's faster
queue = self.queue
out_queue = self.out_queue
thread_stopped = self.thread_stopped
while thread_stopped() is False:
stopped = self.stopped
while stopped() is False:
# grabs Plex item from queue
try:
item = queue.get(block=False)

View File

@ -68,9 +68,9 @@ class Threaded_Process_Metadata(Thread):
item_fct = getattr(itemtypes, self.item_type)
# cache local variables because it's faster
queue = self.queue
thread_stopped = self.thread_stopped
stopped = self.stopped
with item_fct() as item_class:
while thread_stopped() is False:
while stopped() is False:
# grabs item from queue
try:
item = queue.get(block=False)

View File

@ -52,14 +52,13 @@ class Threaded_Show_Sync_Info(Thread):
# cache local variables because it's faster
total = self.total
dialog = DialogProgressBG('dialoglogProgressBG')
thread_stopped = self.thread_stopped
dialog.create("%s %s: %s %s"
% (lang(39714), self.item_type, str(total), lang(39715)))
player = Player()
total = 2 * total
totalProgress = 0
while thread_stopped() is False and not player.isPlaying():
while self.stopped() is False and not player.isPlaying():
with LOCK:
get_progress = GET_METADATA_COUNT
process_progress = PROCESS_METADATA_COUNT

View File

@ -262,8 +262,8 @@ class LibrarySync(Thread):
# Do the processing
for itemtype in process:
if (self.thread_stopped() or
self.thread_suspended() or
if (self.stopped() or
self.suspended() or
not process[itemtype]()):
xbmc.executebuiltin('InhibitIdleShutdown(false)')
js.set_setting('screensaver.mode', screensaver)
@ -705,7 +705,7 @@ class LibrarySync(Thread):
for thread in threads:
# Threads might already have quit by themselves (e.g. Kodi exit)
try:
thread.stop_thread()
thread.stop()
except AttributeError:
pass
log.debug("Stop sent to all threads")
@ -753,7 +753,7 @@ class LibrarySync(Thread):
for view in views:
if self.installSyncDone is not True:
state.PATH_VERIFIED = False
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
# Get items per view
viewId = view['id']
@ -773,7 +773,7 @@ class LibrarySync(Thread):
self.GetAndProcessXMLs(itemType)
# Update viewstate for EVERY item
for view in views:
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
self.PlexUpdateWatched(view['id'], itemType)
@ -847,7 +847,7 @@ class LibrarySync(Thread):
for view in views:
if self.installSyncDone is not True:
state.PATH_VERIFIED = False
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
# Get items per view
viewId = view['id']
@ -876,7 +876,7 @@ class LibrarySync(Thread):
# PROCESS TV Seasons #####
# Cycle through tv shows
for tvShowId in allPlexTvShowsId:
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
# Grab all seasons to tvshow from PMS
seasons = GetAllPlexChildren(tvShowId)
@ -901,7 +901,7 @@ class LibrarySync(Thread):
# PROCESS TV Episodes #####
# Cycle through tv shows
for view in views:
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
# Grab all episodes to tvshow from PMS
episodes = GetAllPlexLeaves(view['id'])
@ -936,7 +936,7 @@ class LibrarySync(Thread):
# Update viewstate:
for view in views:
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
self.PlexUpdateWatched(view['id'], itemType)
@ -973,7 +973,7 @@ class LibrarySync(Thread):
for kind in (v.PLEX_TYPE_ARTIST,
v.PLEX_TYPE_ALBUM,
v.PLEX_TYPE_SONG):
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
log.debug("Start processing music %s" % kind)
self.allKodiElementsId = {}
@ -990,7 +990,7 @@ class LibrarySync(Thread):
# Update viewstate for EVERY item
for view in views:
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
self.PlexUpdateWatched(view['id'], itemType)
@ -1017,7 +1017,7 @@ class LibrarySync(Thread):
for view in views:
if self.installSyncDone is not True:
state.PATH_VERIFIED = False
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
return False
# Get items per view
itemsXML = GetPlexSectionResults(view['id'], args=urlArgs)
@ -1105,7 +1105,7 @@ class LibrarySync(Thread):
now = unix_timestamp()
deleteListe = []
for i, item in enumerate(self.itemsToProcess):
if self.thread_stopped() or self.thread_suspended():
if self.stopped() or self.suspended():
# Chances are that Kodi gets shut down
break
if item['state'] == 9:
@ -1484,8 +1484,8 @@ class LibrarySync(Thread):
def run_internal(self):
# Re-assign handles to have faster calls
thread_stopped = self.thread_stopped
thread_suspended = self.thread_suspended
stopped = self.stopped
suspended = self.suspended
installSyncDone = self.installSyncDone
background_sync = state.BACKGROUND_SYNC
fullSync = self.fullSync
@ -1511,12 +1511,12 @@ class LibrarySync(Thread):
if settings('FanartTV') == 'true':
self.fanartthread.start()
while not thread_stopped():
while not stopped():
# In the event the server goes offline
while thread_suspended():
while suspended():
# Set in service.py
if thread_stopped():
if stopped():
# Abort was requested while waiting. We should exit
log.info("###===--- LibrarySync Stopped ---===###")
return
@ -1613,7 +1613,7 @@ class LibrarySync(Thread):
log.info('Doing scheduled full library scan')
state.DB_SCAN = True
window('plex_dbScan', value="true")
if fullSync() is False and not thread_stopped():
if fullSync() is False and not stopped():
log.error('Could not finish scheduled full sync')
self.force_dialog = True
self.showKodiNote(lang(39410),

View File

@ -149,7 +149,7 @@ class PlayqueueMonitor(Thread):
# Ignore new media added by other addons
continue
for j, old_item in enumerate(old):
if self.thread_stopped():
if self.stopped():
# Chances are that we got an empty Kodi playlist due to
# Kodi exit
return
@ -194,7 +194,7 @@ class PlayqueueMonitor(Thread):
for j in range(i, len(index)):
index[j] += 1
for i in reversed(index):
if self.thread_stopped():
if self.stopped():
# Chances are that we got an empty Kodi playlist due to
# Kodi exit
return
@ -203,12 +203,12 @@ class PlayqueueMonitor(Thread):
LOG.debug('Done comparing playqueues')
def run(self):
thread_stopped = self.thread_stopped
thread_suspended = self.thread_suspended
stopped = self.stopped
suspended = self.suspended
LOG.info("----===## Starting PlayqueueMonitor ##===----")
while not thread_stopped():
while thread_suspended():
if thread_stopped():
while not stopped():
while suspended():
if stopped():
break
sleep(1000)
with LOCK:

View File

@ -287,11 +287,11 @@ class UserClient(Thread):
def run(self):
LOG.info("----===## Starting UserClient ##===----")
thread_stopped = self.thread_stopped
thread_suspended = self.thread_suspended
while not thread_stopped():
while thread_suspended():
if thread_stopped():
stopped = self.stopped
suspended = self.suspended
while not stopped():
while suspended():
if stopped():
break
sleep(1000)

View File

@ -1004,13 +1004,13 @@ def thread_methods(cls=None, add_stops=None, add_suspends=None):
"""
Decorator to add the following methods to a threading class:
suspend_thread(): pauses the thread
resume_thread(): resumes the thread
stop_thread(): stopps/kills the thread
suspend(): pauses the thread
resume(): resumes the thread
stop(): stopps/kills the thread
thread_suspended(): returns True if thread is suspended
thread_stopped(): returns True if thread is stopped (or should stop ;-))
ALSO returns True if PKC should exit
suspended(): returns True if thread is suspended
stopped(): returns True if thread is stopped (or should stop ;-))
ALSO returns True if PKC should exit
Also adds the following class attributes:
thread_stopped
@ -1043,28 +1043,28 @@ def thread_methods(cls=None, add_stops=None, add_suspends=None):
cls.thread_suspended = False
# Define new class methods and attach them to class
def stop_thread(self):
def stop(self):
"""
Call to stop this thread
"""
self.thread_stopped = True
cls.stop_thread = stop_thread
cls.stop = stop
def suspend_thread(self):
def suspend(self):
"""
Call to suspend this thread
"""
self.thread_suspended = True
cls.suspend_thread = suspend_thread
cls.suspend = suspend
def resume_thread(self):
def resume(self):
"""
Call to revive a suspended thread back to life
"""
self.thread_suspended = False
cls.resume_thread = resume_thread
cls.resume = resume
def thread_suspended(self):
def suspended(self):
"""
Returns True if the thread is suspended
"""
@ -1074,9 +1074,9 @@ def thread_methods(cls=None, add_stops=None, add_suspends=None):
if getattr(state, suspend):
return True
return False
cls.thread_suspended = thread_suspended
cls.suspended = suspended
def thread_stopped(self):
def stopped(self):
"""
Returns True if the thread is stopped
"""
@ -1086,7 +1086,7 @@ def thread_methods(cls=None, add_stops=None, add_suspends=None):
if getattr(state, stop):
return True
return False
cls.thread_stopped = thread_stopped
cls.stopped = stopped
# Return class to render this a decorator
return cls

View File

@ -58,16 +58,16 @@ class WebSocket(Thread):
counter = 0
handshake_counter = 0
thread_stopped = self.thread_stopped
thread_suspended = self.thread_suspended
while not thread_stopped():
stopped = self.stopped
suspended = self.suspended
while not stopped():
# In the event the server goes offline
while thread_suspended():
while suspended():
# Set in service.py
if self.ws is not None:
self.ws.close()
self.ws = None
if thread_stopped():
if stopped():
# Abort was requested while waiting. We should exit
LOG.info("##===---- %s Stopped ----===##",
self.__class__.__name__)
@ -255,16 +255,16 @@ class Alexa_Websocket(WebSocket):
pass
# Path in thread_methods
def stop_thread(self):
def stop(self):
self.thread_stopped = True
def suspend_thread(self):
def suspend(self):
self.thread_suspended = True
def resume_thread(self):
def resume(self):
self.thread_suspended = False
def thread_stopped(self):
def stopped(self):
if self.thread_stopped is True:
return True
if state.STOP_PKC:
@ -272,7 +272,7 @@ class Alexa_Websocket(WebSocket):
return False
# The culprit
def thread_suspended(self):
def suspended(self):
"""
Overwrite method since we need to check for plex token
"""