Fix playqueue monitoring locking mechanism

This commit is contained in:
Croneter 2018-04-10 19:23:37 +02:00
parent f6b3dfdf12
commit 1e43f1cc77

View file

@ -226,20 +226,26 @@ class PlayqueueMonitor(Thread):
if stopped(): if stopped():
break break
sleep(1000) sleep(1000)
for playqueue in PLAYQUEUES: work = []
kodi_pl = js.playlist_get_items(playqueue.playlistid) # Detect changed playqueues first, do the work afterwards
if playqueue.old_kodi_pl != kodi_pl: with LOCK:
if playqueue.id is None and (not state.DIRECT_PATHS or for playqueue in PLAYQUEUES:
state.CONTEXT_MENU_PLAY): kodi_pl = js.playlist_get_items(playqueue.playlistid)
# Only initialize if directly fired up using direct if playqueue.old_kodi_pl != kodi_pl:
# paths. Otherwise let default.py do its magic if playqueue.id is None and (not state.DIRECT_PATHS or
LOG.debug('Not yet initiating playback') state.CONTEXT_MENU_PLAY):
elif playqueue.pkc_edit: # Only initialize if directly fired up using direct
playqueue.pkc_edit = False # paths. Otherwise let default.py do its magic
LOG.debug('PKC just edited the playqueue - skipping') LOG.debug('Not yet initiating playback')
else: elif playqueue.pkc_edit:
# compare old and new playqueue playqueue.pkc_edit = False
self._compare_playqueues(playqueue, kodi_pl) LOG.debug('PKC edited the playqueue - skipping')
playqueue.old_kodi_pl = list(kodi_pl) else:
# We do need to update our playqueues
work.append((playqueue, kodi_pl))
playqueue.old_kodi_pl = kodi_pl
# Now do the work - LOCK individual playqueue edits
for playqueue, kodi_pl in work:
self._compare_playqueues(playqueue, kodi_pl)
sleep(200) sleep(200)
LOG.info("----===## PlayqueueMonitor stopped ##===----") LOG.info("----===## PlayqueueMonitor stopped ##===----")