From cc20464c151be408fe5c0a6a218bd89bb1d7257a Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 19 Dec 2020 21:37:39 +0100 Subject: [PATCH] Fix backgroundthreads and TypeError '<' not supported between instances --- resources/lib/backgroundthread.py | 11 +++++++++-- resources/lib/library_sync/sections.py | 7 ++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/resources/lib/backgroundthread.py b/resources/lib/backgroundthread.py index 0af98427..d797df6b 100644 --- a/resources/lib/backgroundthread.py +++ b/resources/lib/backgroundthread.py @@ -6,6 +6,7 @@ import threading import queue import heapq from collections import deque +from functools import total_ordering from . import utils, app, variables as v @@ -279,14 +280,20 @@ class Tasks(list): self.pop().cancel() +@total_ordering class Task(object): def __init__(self, priority=None): self.priority = priority self._canceled = False self.finished = False - def __cmp__(self, other): - return self.priority - other.priority + def __lt__(self, other): + """Magic method Task 0 + + def __eq__(self, other): + """Magic method Task=Other Task; compares the tasks' priorities.""" + return self.priority == other.priority def start(self): BGThreader.addTask(self) diff --git a/resources/lib/library_sync/sections.py b/resources/lib/library_sync/sections.py index 77a65b3d..817b724b 100644 --- a/resources/lib/library_sync/sections.py +++ b/resources/lib/library_sync/sections.py @@ -97,14 +97,15 @@ class Section(object): "}}").format(self=self) def __bool__(self): + """Magic method to compare sections with =. section_id, name and + section_type must be set and be identical.""" return (self.section_id is not None and self.name is not None and self.section_type is not None) def __eq__(self, section): - """ - Sections compare equal if their section_id, name and plex_type (first - prio) OR section_type (if there is no plex_type is set) compare equal + """Sections compare equal if their section_id, name and plex_type (first + prio) OR section_type (if there is no plex_type is set) compare equal. """ return (self.section_id == section.section_id and self.name == section.name and