[kupfer] task: Simplify ThreadTask
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] task: Simplify ThreadTask
- Date: Tue, 25 Aug 2009 13:21:18 +0000 (UTC)
commit c99c78f171d5784d172c6d69e13b4f252114f84b
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Mon Aug 24 15:51:12 2009 +0200
task: Simplify ThreadTask
kupfer/task.py | 22 ++++++----------------
1 files changed, 6 insertions(+), 16 deletions(-)
---
diff --git a/kupfer/task.py b/kupfer/task.py
index d19c82e..1d38f20 100644
--- a/kupfer/task.py
+++ b/kupfer/task.py
@@ -38,13 +38,11 @@ class StepTask (Task):
finally:
self.finish()
-class ThreadTask (Task, threading.Thread):
+class ThreadTask (Task):
"""Run in a thread"""
def __init__(self, name):
Task.__init__(self, name)
- threading.Thread.__init__(self)
- self.__thread_done = False
- self.__thread_started = False
+ self._thread = None
def is_thread(self):
return True
@@ -53,20 +51,12 @@ class ThreadTask (Task, threading.Thread):
"""Override this to run what should be done in the thread"""
raise NotImplementedError
- def __thread_run(self):
- try:
- self.__retval = self.thread_do()
- finally:
- self.__thread_done = True
-
def run(self):
while True:
- if not self.__thread_started:
- # swizzle the methods for Thread
- self.run = self.__thread_run
- self.start()
- self.__thread_started = True
- elif self.__thread_done:
+ if not self._thread:
+ self._thread = threading.Thread(target=self.thread_do)
+ self._thread.start()
+ elif not self._thread.isAlive():
return
yield
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]