##// END OF EJS Templates
add log_errors decorator for on_recv callbacks...
MinRK -
Show More
@@ -25,7 +25,7 b' from zmq.eventloop import ioloop, zmqstream'
25 from IPython.config.configurable import LoggingConfigurable
25 from IPython.config.configurable import LoggingConfigurable
26 from IPython.utils.traitlets import Set, Instance, CFloat, Integer
26 from IPython.utils.traitlets import Set, Instance, CFloat, Integer
27
27
28 from IPython.parallel.util import asbytes
28 from IPython.parallel.util import asbytes, log_errors
29
29
30 class Heart(object):
30 class Heart(object):
31 """A basic heart object for responding to a HeartMonitor.
31 """A basic heart object for responding to a HeartMonitor.
@@ -148,6 +148,7 b' class HeartMonitor(LoggingConfigurable):'
148 self.hearts.remove(heart)
148 self.hearts.remove(heart)
149
149
150
150
151 @log_errors
151 def handle_pong(self, msg):
152 def handle_pong(self, msg):
152 "a heart just beat"
153 "a heart just beat"
153 current = asbytes(str(self.lifetime))
154 current = asbytes(str(self.lifetime))
@@ -454,6 +454,7 b' class Hub(SessionFactory):'
454 #-----------------------------------------------------------------------------
454 #-----------------------------------------------------------------------------
455
455
456
456
457 @util.log_errors
457 def dispatch_monitor_traffic(self, msg):
458 def dispatch_monitor_traffic(self, msg):
458 """all ME and Task queue messages come through here, as well as
459 """all ME and Task queue messages come through here, as well as
459 IOPub traffic."""
460 IOPub traffic."""
@@ -473,6 +474,7 b' class Hub(SessionFactory):'
473 self.log.error("Invalid monitor topic: %r", switch)
474 self.log.error("Invalid monitor topic: %r", switch)
474
475
475
476
477 @util.log_errors
476 def dispatch_query(self, msg):
478 def dispatch_query(self, msg):
477 """Route registration requests and queries from clients."""
479 """Route registration requests and queries from clients."""
478 try:
480 try:
@@ -43,7 +43,7 b' from IPython.config.application import Application'
43 from IPython.config.loader import Config
43 from IPython.config.loader import Config
44 from IPython.utils.traitlets import Instance, Dict, List, Set, Integer, Enum, CBytes
44 from IPython.utils.traitlets import Instance, Dict, List, Set, Integer, Enum, CBytes
45
45
46 from IPython.parallel import error
46 from IPython.parallel import error, util
47 from IPython.parallel.factory import SessionFactory
47 from IPython.parallel.factory import SessionFactory
48 from IPython.parallel.util import connect_logger, local_logger, asbytes
48 from IPython.parallel.util import connect_logger, local_logger, asbytes
49
49
@@ -240,6 +240,8 b' class TaskScheduler(SessionFactory):'
240 # [Un]Registration Handling
240 # [Un]Registration Handling
241 #-----------------------------------------------------------------------
241 #-----------------------------------------------------------------------
242
242
243
244 @util.log_errors
243 def dispatch_notification(self, msg):
245 def dispatch_notification(self, msg):
244 """dispatch register/unregister events."""
246 """dispatch register/unregister events."""
245 try:
247 try:
@@ -343,6 +345,9 b' class TaskScheduler(SessionFactory):'
343 #-----------------------------------------------------------------------
345 #-----------------------------------------------------------------------
344 # Job Submission
346 # Job Submission
345 #-----------------------------------------------------------------------
347 #-----------------------------------------------------------------------
348
349
350 @util.log_errors
346 def dispatch_submission(self, raw_msg):
351 def dispatch_submission(self, raw_msg):
347 """Dispatch job submission to appropriate handlers."""
352 """Dispatch job submission to appropriate handlers."""
348 # ensure targets up to date:
353 # ensure targets up to date:
@@ -560,6 +565,9 b' class TaskScheduler(SessionFactory):'
560 #-----------------------------------------------------------------------
565 #-----------------------------------------------------------------------
561 # Result Handling
566 # Result Handling
562 #-----------------------------------------------------------------------
567 #-----------------------------------------------------------------------
568
569
570 @util.log_errors
563 def dispatch_result(self, raw_msg):
571 def dispatch_result(self, raw_msg):
564 """dispatch method for result replies"""
572 """dispatch method for result replies"""
565 try:
573 try:
@@ -39,6 +39,8 b' except:'
39 import zmq
39 import zmq
40 from zmq.log import handlers
40 from zmq.log import handlers
41
41
42 from IPython.external.decorator import decorator
43
42 # IPython imports
44 # IPython imports
43 from IPython.config.application import Application
45 from IPython.config.application import Application
44 from IPython.utils import py3compat
46 from IPython.utils import py3compat
@@ -106,6 +108,19 b' class ReverseDict(dict):'
106 # Functions
108 # Functions
107 #-----------------------------------------------------------------------------
109 #-----------------------------------------------------------------------------
108
110
111 @decorator
112 def log_errors(f, self, *args, **kwargs):
113 """decorator to log unhandled exceptions raised in a method.
114
115 For use wrapping on_recv callbacks, so that exceptions
116 do not cause the stream to be closed.
117 """
118 try:
119 return f(self, *args, **kwargs)
120 except Exception:
121 self.log.error("Uncaught exception in %r" % f, exc_info=True)
122
123
109 def asbytes(s):
124 def asbytes(s):
110 """ensure that an object is ascii bytes"""
125 """ensure that an object is ascii bytes"""
111 if isinstance(s, unicode):
126 if isinstance(s, unicode):
General Comments 0
You need to be logged in to leave comments. Login now