From 027aac51724492798fd4875ba96dccccd9ac77ad 2014-12-06 15:13:43 From: Bussonnier Matthias Date: 2014-12-06 15:13:43 Subject: [PATCH] lazy load widgets Allow warnign to appear in notebook at the time widets get imported --- diff --git a/IPython/kernel/zmq/ipkernel.py b/IPython/kernel/zmq/ipkernel.py index 89d9677..0143d12 100644 --- a/IPython/kernel/zmq/ipkernel.py +++ b/IPython/kernel/zmq/ipkernel.py @@ -5,7 +5,6 @@ import sys import traceback from IPython.core import release -from IPython.html.widgets import Widget from IPython.utils.py3compat import builtin_mod, PY3 from IPython.utils.tokenutil import token_at_cursor, line_at_cursor from IPython.utils.traitlets import Instance, Type, Any @@ -16,6 +15,12 @@ from .kernelbase import Kernel as KernelBase from .serialize import serialize_object, unpack_apply_message from .zmqshell import ZMQInteractiveShell + +def lazy_import_handle_comm_opened(*args, **kwargs): + from IPython.html.widgets import Widget + Widget.handle_comm_opened(*args, **kwargs) + + class IPythonKernel(KernelBase): shell = Instance('IPython.core.interactiveshell.InteractiveShellABC') shell_class = Type(ZMQInteractiveShell) @@ -59,7 +64,7 @@ class IPythonKernel(KernelBase): self.comm_manager = CommManager(shell=self.shell, parent=self, kernel=self) - self.comm_manager.register_target('ipython.widget', Widget.handle_comm_opened) + self.comm_manager.register_target('ipython.widget', lazy_import_handle_comm_opened) self.shell.configurables.append(self.comm_manager) comm_msg_types = [ 'comm_open', 'comm_msg', 'comm_close' ]