Merge remote-tracking branch 'worker/tasks' into Develop
This commit is contained in:
commit
d406d91856
|
@ -82,16 +82,8 @@ class WorkerThread(threading.Thread):
|
|||
tasks = self.queue.to_list() + self.dequeued
|
||||
return sorted(tasks, 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():
|
||||
item = self.queue.get()
|
||||
|
||||
def cleanup_tasks(self):
|
||||
with self.doLock:
|
||||
# once we hit our trigger, start cleaning up dead tasks
|
||||
if len(self.dequeued) > TASK_CLEANUP_TRIGGER:
|
||||
dead = []
|
||||
alive = []
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
if item.task.stat is STAT_WAITING:
|
||||
# CalibreTask.start() should wrap all exceptions in it's own error handling
|
||||
|
|
Loading…
Reference in New Issue
Block a user