Fix backgroundthreads and TypeError '<' not supported between instances
This commit is contained in:
parent
8bdfcbabc8
commit
cc20464c15
2 changed files with 13 additions and 5 deletions
|
@ -6,6 +6,7 @@ import threading
|
||||||
import queue
|
import queue
|
||||||
import heapq
|
import heapq
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
from functools import total_ordering
|
||||||
|
|
||||||
from . import utils, app, variables as v
|
from . import utils, app, variables as v
|
||||||
|
|
||||||
|
@ -279,14 +280,20 @@ class Tasks(list):
|
||||||
self.pop().cancel()
|
self.pop().cancel()
|
||||||
|
|
||||||
|
|
||||||
|
@total_ordering
|
||||||
class Task(object):
|
class Task(object):
|
||||||
def __init__(self, priority=None):
|
def __init__(self, priority=None):
|
||||||
self.priority = priority
|
self.priority = priority
|
||||||
self._canceled = False
|
self._canceled = False
|
||||||
self.finished = False
|
self.finished = False
|
||||||
|
|
||||||
def __cmp__(self, other):
|
def __lt__(self, other):
|
||||||
return self.priority - other.priority
|
"""Magic method Task<Other Task; compares the tasks' priorities."""
|
||||||
|
return self.priority - other.priority > 0
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
"""Magic method Task=Other Task; compares the tasks' priorities."""
|
||||||
|
return self.priority == other.priority
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
BGThreader.addTask(self)
|
BGThreader.addTask(self)
|
||||||
|
|
|
@ -97,14 +97,15 @@ class Section(object):
|
||||||
"}}").format(self=self)
|
"}}").format(self=self)
|
||||||
|
|
||||||
def __bool__(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
|
return (self.section_id is not None and
|
||||||
self.name is not None and
|
self.name is not None and
|
||||||
self.section_type is not None)
|
self.section_type is not None)
|
||||||
|
|
||||||
def __eq__(self, section):
|
def __eq__(self, section):
|
||||||
"""
|
"""Sections compare equal if their section_id, name and plex_type (first
|
||||||
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.
|
||||||
prio) OR section_type (if there is no plex_type is set) compare equal
|
|
||||||
"""
|
"""
|
||||||
return (self.section_id == section.section_id and
|
return (self.section_id == section.section_id and
|
||||||
self.name == section.name and
|
self.name == section.name and
|
||||||
|
|
Loading…
Reference in a new issue