From 85d4e660ef8f00d1713172619dead1986c91fb47 Mon Sep 17 00:00:00 2001 From: Chuddah Date: Sun, 16 Feb 2020 18:41:14 +0000 Subject: [PATCH] Dont modify a list as you are traversing it. The result is implementation dependant although with CPython elements are unintentionally skipped during iteration. Basic CPython example: >>> A = [1,2,3,4,5,6] >>> for a in A: ... A.remove(a) >>> A [2, 4, 6] --- jellyfin_kodi/library.py | 9 ++++----- jellyfin_kodi/objects/kodi/artwork.py | 4 +--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/jellyfin_kodi/library.py b/jellyfin_kodi/library.py index 180ece7d..0315c25a 100644 --- a/jellyfin_kodi/library.py +++ b/jellyfin_kodi/library.py @@ -131,11 +131,10 @@ class Library(threading.Thread): Start new "daemon threads" to process library updates. (actual daemon thread is not supported in Kodi) ''' - for threads in (self.download_threads, self.writer_threads['updated'], - self.writer_threads['userdata'], self.writer_threads['removed']): - for thread in threads: - if thread.is_done: - threads.remove(thread) + self.download_threads = [thread for thread in self.download_threads if not thread.is_done] + self.writer_threads['updated'] = [thread for thread in self.writer_threads['updated'] if not thread.is_done] + self.writer_threads['userdata'] = [thread for thread in self.writer_threads['userdata'] if not thread.is_done] + self.writer_threads['removed'] = [thread for thread in self.writer_threads['removed'] if not thread.is_done] if not self.player.isPlayingVideo() or settings('syncDuringPlay.bool') or xbmc.getCondVisibility('VideoPlayer.Content(livetv)'): diff --git a/jellyfin_kodi/objects/kodi/artwork.py b/jellyfin_kodi/objects/kodi/artwork.py index 0625d75e..b9fc4f93 100644 --- a/jellyfin_kodi/objects/kodi/artwork.py +++ b/jellyfin_kodi/objects/kodi/artwork.py @@ -147,9 +147,7 @@ class Artwork(object): def add_worker(self): - for thread in self.threads: - if thread.is_done: - self.threads.remove(thread) + self.threads = [thread for thread in self.threads if not thread.is_done] if self.queue.qsize() and len(self.threads) < 2: