##// END OF EJS Templates
Stripping notebook server flags from kernel's argv.
Stripping notebook server flags from kernel's argv.

File last commit:

r4282:1bc3aac5
r4579:f6078d0a
Show More
kernelmanager.py
243 lines | 8.3 KiB | text/x-python | PythonLexer
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 """ Defines a KernelManager that provides signals and slots.
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609 """
# System library imports.
Evan Patterson
Paved the way for PySide support....
r3304 from IPython.external.qt import QtCore
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
# IPython imports.
Brian Granger
Initial support in ipkernel for proper displayhook handling.
r2786 from IPython.utils.traitlets import Type
epatters
* Refactored KernelManager to use Traitlets and to have its channels as attributes...
r2611 from IPython.zmq.kernelmanager import KernelManager, SubSocketChannel, \
MinRK
cleanup channel names to match function not socket...
r3974 ShellSocketChannel, StdInSocketChannel, HBSocketChannel
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 from util import MetaQObjectHasTraits, SuperQObject
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
Brian Granger
Fixed high CPU usage of XREQ channel....
r2695
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 class SocketChannelQObject(SuperQObject):
# Emitted when the channel is started.
Evan Patterson
Paved the way for PySide support....
r3304 started = QtCore.Signal()
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994
# Emitted when the channel is stopped.
Evan Patterson
Paved the way for PySide support....
r3304 stopped = QtCore.Signal()
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994
#---------------------------------------------------------------------------
MinRK
cleanup channel names to match function not socket...
r3974 # 'ZMQSocketChannel' interface
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 #---------------------------------------------------------------------------
def start(self):
""" Reimplemented to emit signal.
"""
super(SocketChannelQObject, self).start()
self.started.emit()
def stop(self):
""" Reimplemented to emit signal.
"""
super(SocketChannelQObject, self).stop()
self.stopped.emit()
MinRK
cleanup channel names to match function not socket...
r3974 class QtShellSocketChannel(SocketChannelQObject, ShellSocketChannel):
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994
# Emitted when any message is received.
Evan Patterson
Paved the way for PySide support....
r3304 message_received = QtCore.Signal(object)
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994
Brian Granger
Added a first_reply signal to the heartbeat channel.
r3024 # Emitted when a reply has been received for the corresponding request
# type.
Evan Patterson
Paved the way for PySide support....
r3304 execute_reply = QtCore.Signal(object)
complete_reply = QtCore.Signal(object)
object_info_reply = QtCore.Signal(object)
Thomas Kluyver
Rename history_tail_reply back to history_reply.
r3820 history_reply = QtCore.Signal(object)
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032 # Emitted when the first reply comes back.
Evan Patterson
Paved the way for PySide support....
r3304 first_reply = QtCore.Signal()
Brian Granger
Added a first_reply signal to the heartbeat channel.
r3024
# Used by the first_reply signal logic to determine if a reply is the
# first.
_handlers_called = False
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 #---------------------------------------------------------------------------
MinRK
cleanup channel names to match function not socket...
r3974 # 'ShellSocketChannel' interface
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 #---------------------------------------------------------------------------
def call_handlers(self, msg):
""" Reimplemented to emit signals instead of making callbacks.
"""
# Emit the generic signal.
self.message_received.emit(msg)
# Emit signals for specialized message types.
Brian E. Granger
Fixing code to assume msg_type and msg_id are top-level....
r4282 msg_type = msg['header']['msg_type']
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 signal = getattr(self, msg_type, None)
if signal:
signal.emit(msg)
Brian Granger
Added a first_reply signal to the heartbeat channel.
r3024 if not self._handlers_called:
self.first_reply.emit()
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032 self._handlers_called = True
Brian Granger
Added a first_reply signal to the heartbeat channel.
r3024
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032 #---------------------------------------------------------------------------
MinRK
cleanup channel names to match function not socket...
r3974 # 'QtShellSocketChannel' interface
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032 #---------------------------------------------------------------------------
Brian Granger
Added a first_reply signal to the heartbeat channel.
r3024
def reset_first_reply(self):
""" Reset the first_reply signal to fire again on the next reply.
"""
self._handlers_called = False
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994
class QtSubSocketChannel(SocketChannelQObject, SubSocketChannel):
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
# Emitted when any message is received.
Evan Patterson
Paved the way for PySide support....
r3304 message_received = QtCore.Signal(object)
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 # Emitted when a message of type 'stream' is received.
Evan Patterson
Paved the way for PySide support....
r3304 stream_received = QtCore.Signal(object)
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 # Emitted when a message of type 'pyin' is received.
Evan Patterson
Paved the way for PySide support....
r3304 pyin_received = QtCore.Signal(object)
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770
# Emitted when a message of type 'pyout' is received.
Evan Patterson
Paved the way for PySide support....
r3304 pyout_received = QtCore.Signal(object)
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770
# Emitted when a message of type 'pyerr' is received.
Evan Patterson
Paved the way for PySide support....
r3304 pyerr_received = QtCore.Signal(object)
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770
Brian Granger
Mostly final version of display data....
r3277 # Emitted when a message of type 'display_data' is received
epatters
Yet more PySide compatibility fixes.
r3307 display_data_received = QtCore.Signal(object)
Brian Granger
Mostly final version of display data....
r3277
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 # Emitted when a crash report message is received from the kernel's
# last-resort sys.excepthook.
Evan Patterson
Paved the way for PySide support....
r3304 crash_received = QtCore.Signal(object)
epatters
* Refactored KernelManager to use Traitlets and to have its channels as attributes...
r2611
MinRK
added shutdown notification handling to ipythonqt
r3090 # Emitted when a shutdown is noticed.
Evan Patterson
Paved the way for PySide support....
r3304 shutdown_reply_received = QtCore.Signal(object)
MinRK
added shutdown notification handling to ipythonqt
r3090
epatters
* Refactored KernelManager to use Traitlets and to have its channels as attributes...
r2611 #---------------------------------------------------------------------------
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609 # 'SubSocketChannel' interface
#---------------------------------------------------------------------------
def call_handlers(self, msg):
""" Reimplemented to emit signals instead of making callbacks.
"""
# Emit the generic signal.
self.message_received.emit(msg)
# Emit signals for specialized message types.
Brian E. Granger
Fixing code to assume msg_type and msg_id are top-level....
r4282 msg_type = msg['header']['msg_type']
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770 signal = getattr(self, msg_type + '_received', None)
if signal:
signal.emit(msg)
elif msg_type in ('stdout', 'stderr'):
self.stream_received.emit(msg)
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
epatters
Added a flush method to the SubSocketChannel. The Qt console frontend now uses this method to ensure that output has been processed before it writes a new prompt.
r2614 def flush(self):
""" Reimplemented to ensure that signals are dispatched immediately.
"""
super(QtSubSocketChannel, self).flush()
QtCore.QCoreApplication.instance().processEvents()
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
MinRK
cleanup channel names to match function not socket...
r3974 class QtStdInSocketChannel(SocketChannelQObject, StdInSocketChannel):
epatters
Initial checkin of Qt kernel manager. Began refactor of FrontendWidget.
r2609
epatters
Basic raw_input implementation is now working.
r2707 # Emitted when any message is received.
Evan Patterson
Paved the way for PySide support....
r3304 message_received = QtCore.Signal(object)
epatters
Basic raw_input implementation is now working.
r2707
epatters
* Change input mechanism: replace raw_input instead of stdin....
r2730 # Emitted when an input request is received.
Evan Patterson
Paved the way for PySide support....
r3304 input_requested = QtCore.Signal(object)
epatters
Basic raw_input implementation is now working.
r2707
epatters
* Refactored KernelManager to use Traitlets and to have its channels as attributes...
r2611 #---------------------------------------------------------------------------
MinRK
cleanup channel names to match function not socket...
r3974 # 'StdInSocketChannel' interface
epatters
Basic raw_input implementation is now working.
r2707 #---------------------------------------------------------------------------
def call_handlers(self, msg):
""" Reimplemented to emit signals instead of making callbacks.
"""
# Emit the generic signal.
self.message_received.emit(msg)
# Emit signals for specialized message types.
Brian E. Granger
Fixing code to assume msg_type and msg_id are top-level....
r4282 msg_type = msg['header']['msg_type']
epatters
* Change input mechanism: replace raw_input instead of stdin....
r2730 if msg_type == 'input_request':
self.input_requested.emit(msg)
epatters
* Refactored KernelManager to use Traitlets and to have its channels as attributes...
r2611
epatters
* Moved KernelManager attribute management code in FrontendWidget into a mixin class usable in any Qt frontend. Registering handlers for message types is now trivial....
r2770
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 class QtHBSocketChannel(SocketChannelQObject, HBSocketChannel):
Brian Granger
Added heartbeat support.
r2910
# Emitted when the kernel has died.
Evan Patterson
Paved the way for PySide support....
r3304 kernel_died = QtCore.Signal(object)
Brian Granger
Added heartbeat support.
r2910
#---------------------------------------------------------------------------
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 # 'HBSocketChannel' interface
Brian Granger
Added heartbeat support.
r2910 #---------------------------------------------------------------------------
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)
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 class QtKernelManager(KernelManager, SuperQObject):
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 """ A KernelManager that provides signals and slots.
epatters
* Refactored KernelManager to use Traitlets and to have its channels as attributes...
r2611 """
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 __metaclass__ = MetaQObjectHasTraits
# Emitted when the kernel manager has started listening.
Evan Patterson
Paved the way for PySide support....
r3304 started_channels = QtCore.Signal()
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
# Emitted when the kernel manager has stopped listening.
Evan Patterson
Paved the way for PySide support....
r3304 stopped_channels = QtCore.Signal()
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
# Use Qt-specific channel classes that emit signals.
Brian Granger
Initial support in ipkernel for proper displayhook handling.
r2786 sub_channel_class = Type(QtSubSocketChannel)
MinRK
cleanup channel names to match function not socket...
r3974 shell_channel_class = Type(QtShellSocketChannel)
stdin_channel_class = Type(QtStdInSocketChannel)
Brian Granger
Added heartbeat support.
r2910 hb_channel_class = Type(QtHBSocketChannel)
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
#---------------------------------------------------------------------------
# 'KernelManager' interface
#---------------------------------------------------------------------------
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032
#------ Kernel process management ------------------------------------------
def start_kernel(self, *args, **kw):
""" Reimplemented for proper heartbeat management.
"""
MinRK
cleanup channel names to match function not socket...
r3974 if self._shell_channel is not None:
self._shell_channel.reset_first_reply()
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032 super(QtKernelManager, self).start_kernel(*args, **kw)
#------ Channel management -------------------------------------------------
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 def start_channels(self, *args, **kw):
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 """ Reimplemented to emit signal.
"""
epatters
* Added support to KernelManager for starting a subset of the four channels....
r2994 super(QtKernelManager, self).start_channels(*args, **kw)
epatters
Merge branch 'kernelmanager' of git://github.com/ellisonbg/ipython into qtfrontend. Fixed breakage and conflicts from merge....
r2701 self.started_channels.emit()
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643
Brian Granger
Kernel manager is cleaned up and simplified. Still bugs though.
r2699 def stop_channels(self):
epatters
* Added 'started_listening' and 'stopped_listening' signals to QtKernelManager. The FrontendWidget listens for these signals....
r2643 """ Reimplemented to emit signal.
"""
Brian Granger
Kernel manager is cleaned up and simplified. Still bugs though.
r2699 super(QtKernelManager, self).stop_channels()
epatters
Merge branch 'kernelmanager' of git://github.com/ellisonbg/ipython into qtfrontend. Fixed breakage and conflicts from merge....
r2701 self.stopped_channels.emit()
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032
@property
MinRK
cleanup channel names to match function not socket...
r3974 def shell_channel(self):
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032 """ Reimplemented for proper heartbeat management.
"""
MinRK
cleanup channel names to match function not socket...
r3974 if self._shell_channel is None:
self._shell_channel = super(QtKernelManager, self).shell_channel
self._shell_channel.first_reply.connect(self._first_reply)
return self._shell_channel
epatters
Integrated the heart beat pausing/unpausing logic with the (Qt)KernelManager.
r3032
#---------------------------------------------------------------------------
# Protected interface
#---------------------------------------------------------------------------
def _first_reply(self):
""" Unpauses the heartbeat channel when the first reply is received on
the execute channel. Note that this will *not* start the heartbeat
channel if it is not already running!
"""
if self._hb_channel is not None:
self._hb_channel.unpause()