[ create a new paste ] login | about

Link: http://codepad.org/euUqWQNb    [ raw code | fork ]

Python, pasted on Dec 17:
diff --git a/circuits/__init__.py b/circuits/__init__.py
--- a/circuits/__init__.py
+++ b/circuits/__init__.py
@@ -21,7 +21,7 @@
 
 from .core import Event
 from .core import task, Worker
-from .core import Debugger, Bridge, Loader, Manager, Timer
 from .core import handler, reprhandler, BaseComponent, Component
+from .core import Debugger, Bridge, Loader, Manager, Timer, TimeoutError
 
 # flake8: noqa
diff --git a/circuits/core/__init__.py b/circuits/core/__init__.py
--- a/circuits/core/__init__.py
+++ b/circuits/core/__init__.py
@@ -11,7 +11,7 @@
 from .events import Event
 from .bridge import Bridge
 from .loader import Loader
-from .manager import Manager
+from .manager import Manager, TimeoutError
 from .handlers import handler, reprhandler
 from .components import BaseComponent, Component
 
@@ -25,7 +25,7 @@
 
 __all__ = (
     "handler", "BaseComponent", "Component", "Event", "task",
-    "Worker", "Bridge", "Debugger", "Timer", "Manager",
+    "Worker", "Bridge", "Debugger", "Timer", "Manager", "TimeoutError",
 )
 
 # flake8: noqa
diff --git a/circuits/core/manager.py b/circuits/core/manager.py
--- a/circuits/core/manager.py
+++ b/circuits/core/manager.py
@@ -33,6 +33,10 @@
 TIMEOUT = 0.1  # 100ms timeout when idle
 
 
+class TimeoutError(Exception):
+    """Raised for events that timedout while waiting/calling"""
+
+
 class UnregistrableError(Exception):
     """Raised if a component cannot be registered as child."""
 
@@ -415,9 +419,14 @@
         def _on_tick(self):
             if state['timeout'] == 0:
                 self.registerTask((state['task_event'],
-                                   state['task'],
+                                   state["task"],
                                    state['parent']))
+                self.removeHandler(state["tick_handler"], "generate_events")
+                raise TimeoutError(state["task_event"])
+
+            print("...")
             state['timeout'] -= 1
+            print state["timeout"]
 
         if not channels:
             channels = (None, )
@@ -428,13 +437,13 @@
             _on_done_handler = self.addHandler(
                 handler("%s_done" % event, channel=channel)(_on_done))
             if state['timeout'] >= 0:
-                _on_tick_handler = self.addHandler(
+                _on_tick_handler = state["tick_handler"] = self.addHandler(
                     handler("generate_events", channel=channel)(_on_tick))
 
         yield state
 
         self.removeHandler(_on_done_handler, "%s_done" % event)
-        if state['timeout'] >= 0:
+        if state['timeout'] > 0:
             self.removeHandler(_on_tick_handler, "generate_events")
 
         if state["event"] is not None:
@@ -700,6 +709,8 @@
                 # self.registerTask((event, value, task))
             elif value is not None:
                 event.value.value = value
+            elif isinstnace(value, Exceptino):
+                raise(value)
         except StopIteration:
             event.waitingHandlers -= 1
             self.unregisterTask((event, task, parent))


Create a new paste based on this one


Comments: