From 69b7f91542b2c1a230b41acd73c8b8f2ba95462c Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 24 Nov 2018 09:53:37 +0100 Subject: [PATCH] New class to run functions as tasks --- resources/lib/backgroundthread.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/resources/lib/backgroundthread.py b/resources/lib/backgroundthread.py index 45c14f87..055f66ef 100644 --- a/resources/lib/backgroundthread.py +++ b/resources/lib/backgroundthread.py @@ -160,6 +160,17 @@ class Task(object): return not self.finished and not self._canceled +def FunctionAsTask(Task): + def __init__(self, function, *args, **kwargs): + self.function = function + self._args = args + self._kwargs = kwargs + super(FunctionAsTask, self).__init__() + + def run(self): + self.function(*self._args, **self._kwargs) + + class MutablePriorityQueue(Queue.PriorityQueue): def _get(self, heappop=heapq.heappop): self.queue.sort()