qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject qpid-proton git commit: improved error handling
Date Sun, 25 Jan 2015 11:25:15 GMT
Repository: qpid-proton
Updated Branches:
  refs/heads/master bcbbf2574 -> dfd9cadd1


improved error handling


Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/dfd9cadd
Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/dfd9cadd
Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/dfd9cadd

Branch: refs/heads/master
Commit: dfd9cadd1119a90537233196b84c961ee8cfc9c6
Parents: bcbbf25
Author: Rafael Schloming <rhs@alum.mit.edu>
Authored: Sun Jan 25 06:24:56 2015 -0500
Committer: Rafael Schloming <rhs@alum.mit.edu>
Committed: Sun Jan 25 06:24:56 2015 -0500

----------------------------------------------------------------------
 proton-c/bindings/python/proton/__init__.py | 14 +++++++-------
 proton-c/bindings/python/proton/reactors.py | 16 ++++++++++------
 2 files changed, 17 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/dfd9cadd/proton-c/bindings/python/proton/__init__.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/__init__.py b/proton-c/bindings/python/proton/__init__.py
index 127ddd4..17cef30 100644
--- a/proton-c/bindings/python/proton/__init__.py
+++ b/proton-c/bindings/python/proton/__init__.py
@@ -3477,19 +3477,19 @@ class Handler(object):
 
 class _cadapter:
 
-  def __init__(self, handler, errors=None):
+  def __init__(self, handler, on_error=None):
     self.handler = handler
-    self.errors = errors
+    self.on_error = on_error
 
   def __call__(self, cevent):
     ev = Event.wrap(cevent)
     try:
       ev.dispatch(self.handler)
     except:
-      if self.errors is None:
+      if self.on_error is None:
         raise
       else:
-        self.errors.append(sys.exc_info())
+        self.on_error(sys.exc_info())
 
 class WrappedHandler(Wrapper):
 
@@ -3497,11 +3497,11 @@ class WrappedHandler(Wrapper):
     Wrapper.__init__(self, impl_or_constructor)
 
   def add(self, handler):
-    impl = _chandler(handler, getattr(self, "errors", None))
+    impl = _chandler(handler, getattr(self, "on_error", None))
     pn_handler_add(self._impl, impl)
     pn_decref(impl)
 
-def _chandler(obj, errors=None):
+def _chandler(obj, on_error=None):
   if obj is None:
     return None
   elif isinstance(obj, WrappedHandler):
@@ -3509,7 +3509,7 @@ def _chandler(obj, errors=None):
     pn_incref(impl)
     return impl
   else:
-    return pn_pyhandler(_cadapter(obj, errors))
+    return pn_pyhandler(_cadapter(obj, on_error))
 
 ###
 # Driver

http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/dfd9cadd/proton-c/bindings/python/proton/reactors.py
----------------------------------------------------------------------
diff --git a/proton-c/bindings/python/proton/reactors.py b/proton-c/bindings/python/proton/reactors.py
index 41e9543..de9752e 100644
--- a/proton-c/bindings/python/proton/reactors.py
+++ b/proton-c/bindings/python/proton/reactors.py
@@ -869,7 +869,7 @@ class Acceptor(Wrapper):
 
 def _wrap_handler(reactor, impl):
     wrapped = WrappedHandler(impl)
-    wrapped.__dict__["errors"] = reactor.errors
+    wrapped.__dict__["on_error"] = reactor.on_error
     return wrapped
 
 class Reactor(Wrapper):
@@ -889,8 +889,12 @@ class Reactor(Wrapper):
     def _init(self):
         self.errors = []
 
+    def on_error(self, info):
+        self.errors.append(info)
+        self.yield_()
+
     def global_(self, handler):
-        impl = _chandler(handler, self.errors)
+        impl = _chandler(handler, self.on_error)
         pn_reactor_global(self._impl, impl)
         pn_decref(impl)
 
@@ -921,13 +925,13 @@ class Reactor(Wrapper):
         pn_reactor_stop(self._impl)
 
     def schedule(self, delay, task):
-        impl = _chandler(task, self.errors)
+        impl = _chandler(task, self.on_error)
         task = Task.wrap(pn_reactor_schedule(self._impl, secs2millis(delay), impl))
         pn_decref(impl)
         return task
 
     def acceptor(self, host, port, handler=None):
-        impl = _chandler(handler, self.errors)
+        impl = _chandler(handler, self.on_error)
         aimpl = pn_reactor_acceptor(self._impl, host, str(port), impl)
         pn_decref(impl)
         if aimpl:
@@ -936,13 +940,13 @@ class Reactor(Wrapper):
             raise IOError("%s (%s:%s)" % (pn_error_text(pn_io_error(pn_reactor_io(self._impl))),
host, port))
 
     def connection(self, handler=None):
-        impl = _chandler(handler, self.errors)
+        impl = _chandler(handler, self.on_error)
         result = Connection.wrap(pn_reactor_connection(self._impl, impl))
         pn_decref(impl)
         return result
 
     def selectable(self, handler=None):
-        impl = _chandler(handler, self.errors)
+        impl = _chandler(handler, self.on_error)
         result = Selectable.wrap(pn_reactor_selectable(self._impl))
         if impl:
             record = pn_selectable_attachments(result._impl)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message