[kupfer] data: Use kupfer.task for Asynchronous tasks
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] data: Use kupfer.task for Asynchronous tasks
- Date: Sun, 23 Aug 2009 11:27:30 +0000 (UTC)
commit 742d56900e71defe8c4b68b54eb8eb37bc51b768
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Sat Aug 22 21:52:53 2009 +0200
data: Use kupfer.task for Asynchronous tasks
kupfer/data.py | 80 ++-----------------------------------------------------
1 files changed, 3 insertions(+), 77 deletions(-)
---
diff --git a/kupfer/data.py b/kupfer/data.py
index f848d0a..cda6942 100644
--- a/kupfer/data.py
+++ b/kupfer/data.py
@@ -12,7 +12,7 @@ gobject.threads_init()
from . import objects
from . import search, learn
-from . import config, pretty, scheduler
+from . import config, pretty, scheduler, task
# "Enums"
# Which pane
@@ -704,6 +704,7 @@ class DataController (gobject.GObject, pretty.OutputMixin):
ctl.connect("search-result", self._pane_search_result, pane)
self.mode = None
self._search_ids = itertools.count(1)
+ self._task_runner = task.TaskRunner(end_on_finish=False)
sch = scheduler.GetScheduler()
sch.connect("load", self._load)
@@ -926,7 +927,7 @@ class DataController (gobject.GObject, pretty.OutputMixin):
self.source_pane.push_source(ret)
return
if action.is_async():
- GetProcessManager().register_action(action, leaf, sobject, ret)
+ self._task_runner.add_task(ret)
self.emit("launched-action", SourceActionMode, leaf, action)
# pane cleared (invalid item) item was invalid
@@ -957,78 +958,3 @@ def GetDataController():
_data_controller = DataController()
return _data_controller
-
-class ActionThread (threading.Thread, gobject.GObject, pretty.OutputMixin):
- """
- signals
- completed (success)
- """
- __gtype_name__= "ActionThread"
- def __init__(self, start_call, finish_call):
- threading.Thread.__init__(self)
- gobject.GObject.__init__(self)
- self.start_call = start_call
- self.finish_call = finish_call
-
- def run(self):
- try:
- ret = self.start_call()
- except StandardError, exc:
- self.output_error("%s: %s" % (type(exc).__name__, exc))
- gobject.idle_add(self.emit, "completed", False)
- else:
- gobject.idle_add(self.finish_call, ret)
- gobject.idle_add(self.emit, "completed", True)
-gobject.signal_new("completed", ActionThread, gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_BOOLEAN, (gobject.TYPE_BOOLEAN, ))
-
-class ProcessManager (gobject.GObject, pretty.OutputMixin):
- """
- signals:
- new-process ()
- completed (success)
- empty ()
- """
- __gtype_name__ = "ProcessManager"
- def __init__(self):
- super(ProcessManager, self).__init__()
- self.queue = {}
- self._process_ids = itertools.count()
-
- def has_queue(self):
- return len(self.queue)
-
- def _thread_completed(self, thread, success, thread_id):
- del self.queue[thread_id]
- self.emit("completed", success)
- self.output_debug("process %d completed success=%s" % (thread_id, success))
- if not self.has_queue():
- self.emit("empty")
-
- def register_action(self, action, leaf, iobj, ret):
- start_cb, finish_cb = ret
- start_cb_composed = lambda : start_cb(leaf, iobj)
-
- at = ActionThread(start_cb_composed, finish_cb)
- thread_id = self._process_ids.next()
- at.connect("completed", self._thread_completed, thread_id)
- self.queue[thread_id] = (leaf, action, iobj)
- self.output_debug("process %d started for %s " % (thread_id, action))
- at.start()
- self.emit("new-process")
-
-gobject.signal_new("new-process", ProcessManager, gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_BOOLEAN, ())
-gobject.signal_new("completed", ProcessManager, gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_BOOLEAN, (gobject.TYPE_BOOLEAN, ))
-gobject.signal_new("empty", ProcessManager, gobject.SIGNAL_RUN_LAST,
- gobject.TYPE_BOOLEAN, ())
-
-_process_manager = None
-
-def GetProcessManager():
- global _process_manager
- if _process_manager is None:
- _process_manager = ProcessManager()
- return _process_manager
-
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]