envisage.plugins.ipython_kernel.kernelapp module

This module contains an extended version of the upstream ipykernel IPKernelApp.

The main reason for extending is to support clean shutdown.

class envisage.plugins.ipython_kernel.kernelapp.IPKernelApp(**kwargs)[source]

Bases: ipykernel.kernelapp.IPKernelApp

Patched version of the IPKernelApp, mostly to support clean shutdown.

cleanup_singletons()[source]

Clear SingletonConfigurable instances.

close()[source]

Undo the effects of the initialize method:

  • free resources allocated during initialization

  • undo changes to global state

close_crash_handler()[source]

Undo the global state change from init_crash_handler.

Restore the sys.excepthook attribute.

close_heartbeat()[source]

Stop the heartbeat thread, by terminating the corresponding zmq.Context.

close_io()[source]

Undo the effects of init_io.

Restores sys module attributes altered by init_io.

close_iopub()[source]

Close iopub-related resources.

close_kernel()[source]

Undo setup from init_kernel.

close_profile_dir()[source]

Undo changes made in init_profile_dir.

close_shell()[source]

Clean up resources allocated by the shell.

close_sockets()[source]

Unbind, close and destroy sockets created by init_sockets.

configure_tornado_logger()[source]

Configure tornado logging.

Adds a NullHandler to the tornado root logger, if there are no handlers already present on that logger. If no tornado handler is present at the time the IO loop is started, tornado will call logging.basicConfig, which isn’t what we want to happen.

Overridden from the base class, which unconditionally adds a new StreamHandler every time.

See also: - https://github.com/tornadoweb/tornado/blob/v6.0.3/tornado/ioloop.py#L427-L445 # noqa: E501 - https://github.com/tornadoweb/tornado/pull/741

init_crash_handler()[source]

Set up a suitable exception hook.

Extended to keep track of the original sys.excepthook value, so that it can be restored later.

init_heartbeat()[source]

start the heart beating

Overridden from the base class in order to swap in our own Heartbeat class in place of the official one. Our Heartbeat class is modified to allow the heartbeat thread to be shut down cleanly.

This override can be removed once we’re on ipkernel 5.x.

init_io()[source]

Redirect input streams and set a display hook.

Extended to store the original sys attributes so that they can be restored later.

init_kernel()[source]

Create the kernel object itself.

Extended to store the original values of IPython.utils.io.stdout and IPython.utils.io.stderr, so that they can be restored later.

log_connection_info()[source]

Display connection info, and store ports.

Overridden to not write information to __stdout__. We don’t usually want this in applications that embed an IPython kernel (as opposed to the case where IPython effectively is the application).

patch_io()[source]

Patch important libraries that can’t handle sys.stdout forwarding.

Overridden from the base class to do nothing.

The base class method monkeypatches faulthandler so that calling faulthandler.enable() while streams are redirected doesn’t fail.

This override bypasses that patching. Users of the Envisage plugin are advised to enable faulthandler (if desired) as part of application setup, before the plugin is started.

Related: https://github.com/ipython/ipykernel/issues/91