##// END OF EJS Templates
Simplify HBChannel inheritance
Thomas Kluyver -
Show More
@@ -11,11 +11,6 b' try:'
11 except ImportError:
11 except ImportError:
12 from Queue import Queue, Empty # Py 2
12 from Queue import Queue, Empty # Py 2
13
13
14 from IPython.kernel.channelsabc import ShellChannelABC, IOPubChannelABC, \
15 StdInChannelABC
16 from IPython.kernel.channels import HBChannel,\
17 make_iopub_socket, make_shell_socket, make_stdin_socket,\
18 InvalidPortNumber, major_protocol_version
19 from IPython.utils.py3compat import string_types, iteritems
14 from IPython.utils.py3compat import string_types, iteritems
20
15
21 # some utilities to validate message structure, these might get moved elsewhere
16 # some utilities to validate message structure, these might get moved elsewhere
@@ -121,15 +116,3 b' class ZMQSocketChannel(object):'
121 def start(self):
116 def start(self):
122 pass
117 pass
123
118
124
125
126 class BlockingHBChannel(HBChannel):
127
128 # This kernel needs quicker monitoring, shorten to 1 sec.
129 # less than 0.5s is unreliable, and will get occasional
130 # false reports of missed beats.
131 time_to_dead = 1.
132
133 def call_handlers(self, since_last_heartbeat):
134 """ Pause beating on missed heartbeat. """
135 pass
@@ -11,8 +11,9 b' except ImportError:'
11 from Queue import Empty # Python 2
11 from Queue import Empty # Python 2
12
12
13 from IPython.utils.traitlets import Type
13 from IPython.utils.traitlets import Type
14 from IPython.kernel.channels import HBChannel
14 from IPython.kernel.client import KernelClient
15 from IPython.kernel.client import KernelClient
15 from .channels import ZMQSocketChannel, BlockingHBChannel
16 from .channels import ZMQSocketChannel
16
17
17 class BlockingKernelClient(KernelClient):
18 class BlockingKernelClient(KernelClient):
18 def wait_for_ready(self):
19 def wait_for_ready(self):
@@ -35,4 +36,4 b' class BlockingKernelClient(KernelClient):'
35 shell_channel_class = Type(ZMQSocketChannel)
36 shell_channel_class = Type(ZMQSocketChannel)
36 iopub_channel_class = Type(ZMQSocketChannel)
37 iopub_channel_class = Type(ZMQSocketChannel)
37 stdin_channel_class = Type(ZMQSocketChannel)
38 stdin_channel_class = Type(ZMQSocketChannel)
38 hb_channel_class = Type(BlockingHBChannel)
39 hb_channel_class = Type(HBChannel)
@@ -210,7 +210,7 b' class HBChannel(ZMQSocketChannel):'
210 as appropriate.
210 as appropriate.
211 """
211 """
212
212
213 time_to_dead = 3.0
213 time_to_dead = 1.
214 socket = None
214 socket = None
215 poller = None
215 poller = None
216 _running = None
216 _running = None
@@ -332,7 +332,7 b' class HBChannel(ZMQSocketChannel):'
332 so that some logic must be done to ensure that the application level
332 so that some logic must be done to ensure that the application level
333 handlers are called in the application thread.
333 handlers are called in the application thread.
334 """
334 """
335 raise NotImplementedError('call_handlers must be defined in a subclass.')
335 pass
336
336
337
337
338 HBChannelABC.register(HBChannel)
338 HBChannelABC.register(HBChannel)
@@ -62,15 +62,26 b' class InProcessChannel(object):'
62
62
63
63
64
64
65 class InProcessHBChannel(InProcessChannel):
65 class InProcessHBChannel(object):
66 """See `IPython.kernel.channels.HBChannel` for docstrings."""
66 """See `IPython.kernel.channels.HBChannel` for docstrings."""
67
67
68 time_to_dead = 3.0
68 time_to_dead = 3.0
69
69
70 def __init__(self, *args, **kwds):
70 def __init__(self, client=None):
71 super(InProcessHBChannel, self).__init__(*args, **kwds)
71 super(InProcessHBChannel, self).__init__()
72 self.client = client
73 self._is_alive = False
72 self._pause = True
74 self._pause = True
73
75
76 def is_alive(self):
77 return self._is_alive
78
79 def start(self):
80 self._is_alive = True
81
82 def stop(self):
83 self._is_alive = False
84
74 def pause(self):
85 def pause(self):
75 self._pause = True
86 self._pause = True
76
87
@@ -19,11 +19,21 b' from IPython.kernel.channels import HBChannel,\\'
19 make_shell_socket, make_iopub_socket, make_stdin_socket
19 make_shell_socket, make_iopub_socket, make_stdin_socket
20 from IPython.kernel import KernelClient
20 from IPython.kernel import KernelClient
21
21
22 from .kernel_mixins import (QtHBChannelMixin, QtKernelClientMixin)
22 from .kernel_mixins import QtKernelClientMixin
23 from .util import SuperQObject
23 from .util import SuperQObject
24
24
25 class QtHBChannel(QtHBChannelMixin, HBChannel):
25 class QtHBChannel(SuperQObject, HBChannel):
26 pass
26 # A longer timeout than the base class
27 time_to_dead = 3.0
28
29 # Emitted when the kernel has died.
30 kernel_died = QtCore.Signal(object)
31
32 def call_handlers(self, since_last_heartbeat):
33 """ Reimplemented to emit signals instead of making callbacks.
34 """
35 # Emit the generic signal.
36 self.kernel_died.emit(since_last_heartbeat)
27
37
28 from IPython.core.release import kernel_protocol_version_info
38 from IPython.core.release import kernel_protocol_version_info
29
39
@@ -10,16 +10,13 b' from IPython.kernel.inprocess.channels import InProcessChannel'
10
10
11 from IPython.utils.traitlets import Type
11 from IPython.utils.traitlets import Type
12 from .kernel_mixins import ( ChannelQObject,
12 from .kernel_mixins import ( ChannelQObject,
13 QtHBChannelMixin, QtKernelClientMixin,
13 QtKernelClientMixin,
14 QtKernelManagerMixin,
14 QtKernelManagerMixin,
15 )
15 )
16
16
17 class QtInProcessChannel(ChannelQObject, InProcessChannel):
17 class QtInProcessChannel(ChannelQObject, InProcessChannel):
18 pass
18 pass
19
19
20 class QtInProcessHBChannel(QtHBChannelMixin, InProcessHBChannel):
21 pass
22
23 class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient):
20 class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient):
24 """ An in-process KernelManager with signals and slots.
21 """ An in-process KernelManager with signals and slots.
25 """
22 """
@@ -27,7 +24,7 b' class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient):'
27 iopub_channel_class = Type(QtInProcessChannel)
24 iopub_channel_class = Type(QtInProcessChannel)
28 shell_channel_class = Type(QtInProcessChannel)
25 shell_channel_class = Type(QtInProcessChannel)
29 stdin_channel_class = Type(QtInProcessChannel)
26 stdin_channel_class = Type(QtInProcessChannel)
30 hb_channel_class = Type(QtInProcessHBChannel)
27 hb_channel_class = Type(InProcessHBChannel)
31
28
32 class QtInProcessKernelManager(QtKernelManagerMixin, InProcessKernelManager):
29 class QtInProcessKernelManager(QtKernelManagerMixin, InProcessKernelManager):
33 client_class = __module__ + '.QtInProcessKernelClient'
30 client_class = __module__ + '.QtInProcessKernelClient'
@@ -53,17 +53,6 b' class ChannelQObject(SuperQObject):'
53 self.process_events()
53 self.process_events()
54
54
55
55
56 class QtHBChannelMixin(ChannelQObject):
57
58 # Emitted when the kernel has died.
59 kernel_died = QtCore.Signal(object)
60
61 def call_handlers(self, since_last_heartbeat):
62 """ Reimplemented to emit signals instead of making callbacks.
63 """
64 self.kernel_died.emit(since_last_heartbeat)
65
66
67 class QtKernelRestarterMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
56 class QtKernelRestarterMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})):
68
57
69 _timer = None
58 _timer = None
General Comments 0
You need to be logged in to leave comments. Login now