sort tasks only on first element
This commit is contained in:
parent
1114f9099b
commit
6ed6e6bb95
1 changed files with 13 additions and 3 deletions
16
oml/tasks.py
16
oml/tasks.py
|
@ -15,6 +15,16 @@ logger = logging.getLogger(__name__)
|
|||
|
||||
DEUBG_TASKS = False
|
||||
|
||||
class QueueElement(tuple):
|
||||
def __lt__(self, rhs):
|
||||
return self[0] < rhs[0]
|
||||
def __gt__(self, rhs):
|
||||
return self[0] > rhs[0]
|
||||
def __le__(self, rhs):
|
||||
return self[0] <= rhs[0]
|
||||
def __ge__(self, rhs):
|
||||
return self[0] >= rhs[0]
|
||||
|
||||
class Tasks(Thread):
|
||||
_tasks = []
|
||||
|
||||
|
@ -81,7 +91,7 @@ class Tasks(Thread):
|
|||
tasks = json.load(f)
|
||||
for task in tasks:
|
||||
if len(task) == 2:
|
||||
self.q.put((task[0], tuple(task[1])))
|
||||
self.q.put(QueueElement((task[0], tuple(task[1]))))
|
||||
logger.debug('loaded %s tasks', len(tasks))
|
||||
except:
|
||||
logger.debug('failed to load saved tasks', exc_info=True)
|
||||
|
@ -94,7 +104,7 @@ class Tasks(Thread):
|
|||
json.dump(self._tasks, f)
|
||||
|
||||
def join(self):
|
||||
self.q.put((1000, None))
|
||||
self.q.put(QueueElement((1000, None)))
|
||||
r = Thread.join(self)
|
||||
self.save_tasks()
|
||||
return r
|
||||
|
@ -110,6 +120,6 @@ class Tasks(Thread):
|
|||
priority -= 2
|
||||
if not state.shutdown:
|
||||
#logger.debug('queue: %s (%s)', action, data)
|
||||
self.q.put((priority, (action, data)))
|
||||
self.q.put(QueueElement((priority, (action, data))))
|
||||
else:
|
||||
self._tasks.append((priority, (action, data)))
|
||||
|
|
Loading…
Reference in a new issue