##// END OF EJS Templates
remove redundant time_to_dead from IOLoopKernelRestarter
MinRK -
Show More
@@ -1,59 +1,55 b''
1 """A basic in process kernel monitor with autorestarting.
1 """A basic in process kernel monitor with autorestarting.
2
2
3 This watches a kernel's state using KernelManager.is_alive and auto
3 This watches a kernel's state using KernelManager.is_alive and auto
4 restarts the kernel if it dies.
4 restarts the kernel if it dies.
5 """
5 """
6
6
7 #-----------------------------------------------------------------------------
7 #-----------------------------------------------------------------------------
8 # Copyright (C) 2013 The IPython Development Team
8 # Copyright (C) 2013 The IPython Development Team
9 #
9 #
10 # Distributed under the terms of the BSD License. The full license is in
10 # Distributed under the terms of the BSD License. The full license is in
11 # the file COPYING, distributed as part of this software.
11 # the file COPYING, distributed as part of this software.
12 #-----------------------------------------------------------------------------
12 #-----------------------------------------------------------------------------
13
13
14 #-----------------------------------------------------------------------------
14 #-----------------------------------------------------------------------------
15 # Imports
15 # Imports
16 #-----------------------------------------------------------------------------
16 #-----------------------------------------------------------------------------
17
17
18 from __future__ import absolute_import
18 from __future__ import absolute_import
19
19
20 import zmq
20 import zmq
21 from zmq.eventloop import ioloop
21 from zmq.eventloop import ioloop
22
22
23
23
24 from IPython.kernel.restarter import KernelRestarter
24 from IPython.kernel.restarter import KernelRestarter
25 from IPython.utils.traitlets import (
25 from IPython.utils.traitlets import (
26 Instance, Float, List,
26 Instance, Float, List,
27 )
27 )
28
28
29 #-----------------------------------------------------------------------------
29 #-----------------------------------------------------------------------------
30 # Code
30 # Code
31 #-----------------------------------------------------------------------------
31 #-----------------------------------------------------------------------------
32
32
33 class IOLoopKernelRestarter(KernelRestarter):
33 class IOLoopKernelRestarter(KernelRestarter):
34 """Monitor and autorestart a kernel."""
34 """Monitor and autorestart a kernel."""
35
35
36 loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=False)
36 loop = Instance('zmq.eventloop.ioloop.IOLoop', allow_none=False)
37 def _loop_default(self):
37 def _loop_default(self):
38 return ioloop.IOLoop.instance()
38 return ioloop.IOLoop.instance()
39
39
40 time_to_dead = Float(3.0, config=True,
41 help="""Kernel heartbeat interval in seconds."""
42 )
43
44 _pcallback = None
40 _pcallback = None
45
41
46 def start(self):
42 def start(self):
47 """Start the polling of the kernel."""
43 """Start the polling of the kernel."""
48 if self._pcallback is None:
44 if self._pcallback is None:
49 self._pcallback = ioloop.PeriodicCallback(
45 self._pcallback = ioloop.PeriodicCallback(
50 self.poll, 1000*self.time_to_dead, self.loop
46 self.poll, 1000*self.time_to_dead, self.loop
51 )
47 )
52 self._pcallback.start()
48 self._pcallback.start()
53
49
54 def stop(self):
50 def stop(self):
55 """Stop the kernel polling."""
51 """Stop the kernel polling."""
56 if self._pcallback is not None:
52 if self._pcallback is not None:
57 self._pcallback.stop()
53 self._pcallback.stop()
58 self._pcallback = None
54 self._pcallback = None
59
55
General Comments 0
You need to be logged in to leave comments. Login now