diff --git a/IPython/kernel/blocking/channels.py b/IPython/kernel/blocking/channels.py index 7ff0b3d..c4d4a92 100644 --- a/IPython/kernel/blocking/channels.py +++ b/IPython/kernel/blocking/channels.py @@ -11,11 +11,6 @@ try: except ImportError: from Queue import Queue, Empty # Py 2 -from IPython.kernel.channelsabc import ShellChannelABC, IOPubChannelABC, \ - StdInChannelABC -from IPython.kernel.channels import HBChannel,\ - make_iopub_socket, make_shell_socket, make_stdin_socket,\ - InvalidPortNumber, major_protocol_version from IPython.utils.py3compat import string_types, iteritems # some utilities to validate message structure, these might get moved elsewhere @@ -121,15 +116,3 @@ class ZMQSocketChannel(object): def start(self): pass - - -class BlockingHBChannel(HBChannel): - - # This kernel needs quicker monitoring, shorten to 1 sec. - # less than 0.5s is unreliable, and will get occasional - # false reports of missed beats. - time_to_dead = 1. - - def call_handlers(self, since_last_heartbeat): - """ Pause beating on missed heartbeat. """ - pass diff --git a/IPython/kernel/blocking/client.py b/IPython/kernel/blocking/client.py index ddcbcb1..054317a 100644 --- a/IPython/kernel/blocking/client.py +++ b/IPython/kernel/blocking/client.py @@ -11,8 +11,9 @@ except ImportError: from Queue import Empty # Python 2 from IPython.utils.traitlets import Type +from IPython.kernel.channels import HBChannel from IPython.kernel.client import KernelClient -from .channels import ZMQSocketChannel, BlockingHBChannel +from .channels import ZMQSocketChannel class BlockingKernelClient(KernelClient): def wait_for_ready(self): @@ -35,4 +36,4 @@ class BlockingKernelClient(KernelClient): shell_channel_class = Type(ZMQSocketChannel) iopub_channel_class = Type(ZMQSocketChannel) stdin_channel_class = Type(ZMQSocketChannel) - hb_channel_class = Type(BlockingHBChannel) + hb_channel_class = Type(HBChannel) diff --git a/IPython/kernel/channels.py b/IPython/kernel/channels.py index efa58ba..d4d98e2 100644 --- a/IPython/kernel/channels.py +++ b/IPython/kernel/channels.py @@ -210,7 +210,7 @@ class HBChannel(ZMQSocketChannel): as appropriate. """ - time_to_dead = 3.0 + time_to_dead = 1. socket = None poller = None _running = None @@ -332,7 +332,7 @@ class HBChannel(ZMQSocketChannel): so that some logic must be done to ensure that the application level handlers are called in the application thread. """ - raise NotImplementedError('call_handlers must be defined in a subclass.') + pass HBChannelABC.register(HBChannel) diff --git a/IPython/kernel/inprocess/channels.py b/IPython/kernel/inprocess/channels.py index a5cacd2..b6e3c99 100644 --- a/IPython/kernel/inprocess/channels.py +++ b/IPython/kernel/inprocess/channels.py @@ -62,15 +62,26 @@ class InProcessChannel(object): -class InProcessHBChannel(InProcessChannel): +class InProcessHBChannel(object): """See `IPython.kernel.channels.HBChannel` for docstrings.""" time_to_dead = 3.0 - def __init__(self, *args, **kwds): - super(InProcessHBChannel, self).__init__(*args, **kwds) + def __init__(self, client=None): + super(InProcessHBChannel, self).__init__() + self.client = client + self._is_alive = False self._pause = True + def is_alive(self): + return self._is_alive + + def start(self): + self._is_alive = True + + def stop(self): + self._is_alive = False + def pause(self): self._pause = True diff --git a/IPython/qt/client.py b/IPython/qt/client.py index 9a1c07e..45f9832 100644 --- a/IPython/qt/client.py +++ b/IPython/qt/client.py @@ -19,11 +19,21 @@ from IPython.kernel.channels import HBChannel,\ make_shell_socket, make_iopub_socket, make_stdin_socket from IPython.kernel import KernelClient -from .kernel_mixins import (QtHBChannelMixin, QtKernelClientMixin) +from .kernel_mixins import QtKernelClientMixin from .util import SuperQObject -class QtHBChannel(QtHBChannelMixin, HBChannel): - pass +class QtHBChannel(SuperQObject, HBChannel): + # A longer timeout than the base class + time_to_dead = 3.0 + + # Emitted when the kernel has died. + kernel_died = QtCore.Signal(object) + + def call_handlers(self, since_last_heartbeat): + """ Reimplemented to emit signals instead of making callbacks. + """ + # Emit the generic signal. + self.kernel_died.emit(since_last_heartbeat) from IPython.core.release import kernel_protocol_version_info diff --git a/IPython/qt/inprocess.py b/IPython/qt/inprocess.py index 08e10dc..0cabe83 100644 --- a/IPython/qt/inprocess.py +++ b/IPython/qt/inprocess.py @@ -10,16 +10,13 @@ from IPython.kernel.inprocess.channels import InProcessChannel from IPython.utils.traitlets import Type from .kernel_mixins import ( ChannelQObject, - QtHBChannelMixin, QtKernelClientMixin, + QtKernelClientMixin, QtKernelManagerMixin, ) class QtInProcessChannel(ChannelQObject, InProcessChannel): pass -class QtInProcessHBChannel(QtHBChannelMixin, InProcessHBChannel): - pass - class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient): """ An in-process KernelManager with signals and slots. """ @@ -27,7 +24,7 @@ class QtInProcessKernelClient(QtKernelClientMixin, InProcessKernelClient): iopub_channel_class = Type(QtInProcessChannel) shell_channel_class = Type(QtInProcessChannel) stdin_channel_class = Type(QtInProcessChannel) - hb_channel_class = Type(QtInProcessHBChannel) + hb_channel_class = Type(InProcessHBChannel) class QtInProcessKernelManager(QtKernelManagerMixin, InProcessKernelManager): client_class = __module__ + '.QtInProcessKernelClient' diff --git a/IPython/qt/kernel_mixins.py b/IPython/qt/kernel_mixins.py index df80345..b7963f3 100644 --- a/IPython/qt/kernel_mixins.py +++ b/IPython/qt/kernel_mixins.py @@ -53,17 +53,6 @@ class ChannelQObject(SuperQObject): self.process_events() -class QtHBChannelMixin(ChannelQObject): - - # Emitted when the kernel has died. - kernel_died = QtCore.Signal(object) - - def call_handlers(self, since_last_heartbeat): - """ Reimplemented to emit signals instead of making callbacks. - """ - self.kernel_died.emit(since_last_heartbeat) - - class QtKernelRestarterMixin(MetaQObjectHasTraits('NewBase', (HasTraits, SuperQObject), {})): _timer = None