From 0d0437b5c9fcd277ec68b8ee8f1a260c808b33e5 2012-05-15 01:34:18 From: MinRK <benjaminrk@gmail.com> Date: 2012-05-15 01:34:18 Subject: [PATCH] undo initial clobbering done by init_sys_modules in embed_kernel revealed by test added in previous commit. --- diff --git a/IPython/zmq/ipkernel.py b/IPython/zmq/ipkernel.py index 2c8f17d..4c193a0 100755 --- a/IPython/zmq/ipkernel.py +++ b/IPython/zmq/ipkernel.py @@ -887,6 +887,13 @@ def embed_kernel(module=None, local_ns=None, **kwargs): else: app = IPKernelApp.instance(**kwargs) app.initialize([]) + # Undo unnecessary sys module mangling from init_sys_modules. + # This would not be necessary if we could prevent it + # in the first place by using a different InteractiveShell + # subclass, as in the regular embed case. + main = app.kernel.shell._orig_sys_modules_main_mod + if main is not None: + sys.modules[app.kernel.shell._orig_sys_modules_main_name] = main # load the calling scope if not given (caller_module, caller_locals) = extract_module_locals(1)