Show More
@@ -19,7 +19,7 b' It is an incomplete base class, and must be subclassed.' | |||||
19 |
|
19 | |||
20 | from IPython.config.configurable import LoggingConfigurable |
|
20 | from IPython.config.configurable import LoggingConfigurable | |
21 | from IPython.utils.traitlets import ( |
|
21 | from IPython.utils.traitlets import ( | |
22 | Instance, Float, Dict, |
|
22 | Instance, Float, Dict, Bool, | |
23 | ) |
|
23 | ) | |
24 |
|
24 | |||
25 | #----------------------------------------------------------------------------- |
|
25 | #----------------------------------------------------------------------------- | |
@@ -34,6 +34,9 b' class KernelRestarter(LoggingConfigurable):' | |||||
34 | time_to_dead = Float(3.0, config=True, |
|
34 | time_to_dead = Float(3.0, config=True, | |
35 | help="""Kernel heartbeat interval in seconds.""" |
|
35 | help="""Kernel heartbeat interval in seconds.""" | |
36 | ) |
|
36 | ) | |
|
37 | ||||
|
38 | _restarting = Bool(True) | |||
|
39 | ||||
37 | callbacks = Dict() |
|
40 | callbacks = Dict() | |
38 | def _callbacks_default(self): |
|
41 | def _callbacks_default(self): | |
39 | return dict(restart=[], dead=[]) |
|
42 | return dict(restart=[], dead=[]) | |
@@ -71,13 +74,23 b' class KernelRestarter(LoggingConfigurable):' | |||||
71 | except ValueError: |
|
74 | except ValueError: | |
72 | pass |
|
75 | pass | |
73 |
|
76 | |||
|
77 | def _fire_callbacks(self, event): | |||
|
78 | """fire our callbacks for a particular event""" | |||
|
79 | for callback in self.callbacks[event]: | |||
|
80 | try: | |||
|
81 | callback() | |||
|
82 | except Exception as e: | |||
|
83 | self.log.error("KernelRestarter: %s callback %r failed", event, callback, exc_info=True) | |||
|
84 | ||||
74 | def poll(self): |
|
85 | def poll(self): | |
75 | self.log.debug('Polling kernel...') |
|
86 | self.log.debug('Polling kernel...') | |
76 | if not self.kernel_manager.is_alive(): |
|
87 | if not self.kernel_manager.is_alive(): | |
77 | self.log.info('KernelRestarter: restarting kernel') |
|
88 | if self._restarting: | |
78 | for callback in self.callbacks['restart']: |
|
89 | self.log.warn("KernelRestarter: restart failed") | |
79 | try: |
|
90 | self._fire_callbacks('dead') | |
80 | callback() |
|
91 | self._restarting = False | |
81 | except Exception as e: |
|
92 | else: | |
82 | self.log.error("Kernel restart callback %r failed", callback, exc_info=True) |
|
93 | self.log.info('KernelRestarter: restarting kernel') | |
83 | self.kernel_manager.restart_kernel(now=True) |
|
94 | self._fire_callbacks('restart') | |
|
95 | self.kernel_manager.restart_kernel(now=True) | |||
|
96 | self._restarting = True |
General Comments 0
You need to be logged in to leave comments.
Login now