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,6 +226,9 @@ class PlayqueueMonitor(Thread):
if stopped(): if stopped():
break break
sleep(1000) sleep(1000)
work = []
# Detect changed playqueues first, do the work afterwards
with LOCK:
for playqueue in PLAYQUEUES: for playqueue in PLAYQUEUES:
kodi_pl = js.playlist_get_items(playqueue.playlistid) kodi_pl = js.playlist_get_items(playqueue.playlistid)
if playqueue.old_kodi_pl != kodi_pl: if playqueue.old_kodi_pl != kodi_pl:
@ -236,10 +239,13 @@ class PlayqueueMonitor(Thread):
LOG.debug('Not yet initiating playback') LOG.debug('Not yet initiating playback')
elif playqueue.pkc_edit: elif playqueue.pkc_edit:
playqueue.pkc_edit = False playqueue.pkc_edit = False
LOG.debug('PKC just edited the playqueue - skipping') LOG.debug('PKC edited the playqueue - skipping')
else: else:
# compare old and new playqueue # 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) self._compare_playqueues(playqueue, kodi_pl)
playqueue.old_kodi_pl = list(kodi_pl)
sleep(200) sleep(200)
LOG.info("----===## PlayqueueMonitor stopped ##===----") LOG.info("----===## PlayqueueMonitor stopped ##===----")