Merge remote-tracking branch 'worker/tasks' into Develop

pull/1620/head
OzzieIsaacs 4 years ago
commit d406d91856

@ -82,16 +82,8 @@ class WorkerThread(threading.Thread):
tasks = self.queue.to_list() + self.dequeued tasks = self.queue.to_list() + self.dequeued
return sorted(tasks, key=lambda x: x.num) return sorted(tasks, key=lambda x: x.num)
def cleanup_tasks(self):
# Main thread loop starting the different tasks
def run(self):
main_thread = _get_main_thread()
while main_thread.is_alive():
item = self.queue.get()
with self.doLock: with self.doLock:
# once we hit our trigger, start cleaning up dead tasks
if len(self.dequeued) > TASK_CLEANUP_TRIGGER:
dead = [] dead = []
alive = [] alive = []
for x in self.dequeued: for x in self.dequeued:
@ -106,9 +98,21 @@ class WorkerThread(threading.Thread):
ret = sorted(dead, key=lambda x: x.task.end_time)[-TASK_CLEANUP_TRIGGER:] + alive ret = sorted(dead, key=lambda x: x.task.end_time)[-TASK_CLEANUP_TRIGGER:] + alive
self.dequeued = sorted(ret, key=lambda x: x.num) self.dequeued = sorted(ret, key=lambda x: x.num)
# Main thread loop starting the different tasks
def run(self):
main_thread = _get_main_thread()
while main_thread.is_alive():
# this blocks until something is available
item = self.queue.get()
with self.doLock:
# add to list so that in-progress tasks show up # add to list so that in-progress tasks show up
self.dequeued.append(item) self.dequeued.append(item)
# once we hit our trigger, start cleaning up dead tasks
if len(self.dequeued) > TASK_CLEANUP_TRIGGER:
self.cleanup_tasks()
# sometimes tasks (like Upload) don't actually have work to do and are created as already finished # sometimes tasks (like Upload) don't actually have work to do and are created as already finished
if item.task.stat is STAT_WAITING: if item.task.stat is STAT_WAITING:
# CalibreTask.start() should wrap all exceptions in it's own error handling # CalibreTask.start() should wrap all exceptions in it's own error handling

Loading…
Cancel
Save