client.py
71 lines
| 2.3 KiB
| text/x-python
|
PythonLexer
MinRK
|
r10288 | """ Defines a KernelClient that provides signals and slots. | ||
epatters
|
r2609 | """ | ||
Thomas Kluyver
|
r19209 | import atexit | ||
import errno | ||||
from threading import Thread | ||||
import time | ||||
import zmq | ||||
# import ZMQError in top-level namespace, to avoid ugly attribute-error messages | ||||
# during garbage collection of threads at exit: | ||||
from zmq import ZMQError | ||||
from zmq.eventloop import ioloop, zmqstream | ||||
from IPython.external.qt import QtCore | ||||
epatters
|
r2609 | |||
MinRK
|
r10288 | # Local imports | ||
Thomas Kluyver
|
r19224 | from IPython.utils.traitlets import Type, Instance | ||
Thomas Kluyver
|
r19442 | from IPython.kernel.channels import HBChannel | ||
MinRK
|
r10288 | from IPython.kernel import KernelClient | ||
Björn Linse
|
r19644 | from IPython.kernel.channels import InvalidPortNumber | ||
from IPython.kernel.threaded import ThreadedKernelClient, ThreadedZMQSocketChannel | ||||
epatters
|
r2609 | |||
Thomas Kluyver
|
r19227 | from .kernel_mixins import QtKernelClientMixin | ||
Thomas Kluyver
|
r19209 | from .util import SuperQObject | ||
Brian Granger
|
r2695 | |||
Thomas Kluyver
|
r19227 | 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) | ||||
Brian Granger
|
r3277 | |||
Thomas Kluyver
|
r19209 | from IPython.core.release import kernel_protocol_version_info | ||
epatters
|
r2611 | |||
Thomas Kluyver
|
r19209 | major_protocol_version = kernel_protocol_version_info[0] | ||
Björn Linse
|
r19644 | class QtZMQSocketChannel(ThreadedZMQSocketChannel,SuperQObject): | ||
Thomas Kluyver
|
r19225 | """A ZMQ socket emitting a Qt signal when a message is received.""" | ||
Thomas Kluyver
|
r19209 | message_received = QtCore.Signal(object) | ||
def process_events(self): | ||||
""" Process any pending GUI events. | ||||
""" | ||||
QtCore.QCoreApplication.instance().processEvents() | ||||
def call_handlers(self, msg): | ||||
"""This method is called in the ioloop thread when a message arrives. | ||||
It is important to remember that this method is called in the thread | ||||
so that some logic must be done to ensure that the application level | ||||
handlers are called in the application thread. | ||||
""" | ||||
# Emit the generic signal. | ||||
self.message_received.emit(msg) | ||||
Thomas Kluyver
|
r19221 | |||
Björn Linse
|
r19644 | class QtKernelClient(QtKernelClientMixin, ThreadedKernelClient): | ||
MinRK
|
r10288 | """ A KernelClient that provides signals and slots. | ||
epatters
|
r2611 | """ | ||
Thomas Kluyver
|
r19224 | |||
Thomas Kluyver
|
r19221 | iopub_channel_class = Type(QtZMQSocketChannel) | ||
Thomas Kluyver
|
r19220 | shell_channel_class = Type(QtZMQSocketChannel) | ||
stdin_channel_class = Type(QtZMQSocketChannel) | ||||
Brian Granger
|
r9120 | hb_channel_class = Type(QtHBChannel) | ||