Permalink
Browse files

add IPython.parallel.bind_kernel

for using an Engine's Kernel with connecting frontends.
  • Loading branch information...
1 parent e0b0d5e commit 64f2f8d0388a742c51ceca4ec2cf026e3bea6213 @minrk committed May 23, 2012
Showing with 37 additions and 10 deletions.
  1. +3 −3 IPython/lib/kernel.py
  2. +21 −0 IPython/parallel/__init__.py
  3. +13 −7 IPython/parallel/apps/ipengineapp.py
View
6 IPython/lib/kernel.py
@@ -46,11 +46,11 @@ def get_connection_file(app=None):
If unspecified, the currently running app will be used
"""
if app is None:
- from IPython.zmq.kernelapp import KernelApp
- if not KernelApp.initialized():
+ from IPython.zmq.ipkernel import IPKernelApp
+ if not IPKernelApp.initialized():
raise RuntimeError("app not specified, and not in a running Kernel")
- app = KernelApp.instance()
+ app = IPKernelApp.instance()
return filefind(app.connection_file, ['.', app.profile_dir.security_dir])
def find_connection_file(filename, profile=None):
View
21 IPython/parallel/__init__.py
@@ -38,4 +38,25 @@
from .util import interactive
from .controller.dependency import *
+#-----------------------------------------------------------------------------
+# Functions
+#-----------------------------------------------------------------------------
+
+
+def bind_kernel(**kwargs):
+ """Bind an Engine's Kernel to be used as a full IPython kernel.
+
+ This allows a running Engine to be used simultaneously as a full IPython kernel
+ with the QtConsole or other frontends.
+
+ This function returns immediately.
+ """
+ from IPython.parallel.apps.ipengineapp import IPEngineApp
+ if IPEngineApp.initialized():
+ app = IPEngineApp.instance()
+ else:
+ raise RuntimeError("Must be called from an IPEngineApp instance")
+
+ return app.bind_kernel(**kwargs)
+
View
20 IPython/parallel/apps/ipengineapp.py
@@ -230,19 +230,25 @@ def load_connector_file(self):
except AttributeError:
config.EngineFactory.sshserver = d['ssh']
- def listen_kernel(self):
- """setup engine as listening Kernel, for frontends"""
+ def bind_kernel(self, **kwargs):
+ """Promote engine to listening kernel, accessible to frontends."""
if self.kernel_app is not None:
return
- self.log.info("Opening ports for direct connections")
+ self.log.info("Opening ports for direct connections as an IPython kernel")
kernel = self.kernel
- app = self.kernel_app = IPKernelApp(log=self.log, config=self.config,
- profile_dir = self.profile_dir,
- session=self.engine.session,
- )
+ kwargs.setdefault('config', self.config)
+ kwargs.setdefault('log', self.log)
+ kwargs.setdefault('profile_dir', self.profile_dir)
+ kwargs.setdefault('session', self.engine.session)
+
+ app = self.kernel_app = IPKernelApp(**kwargs)
+
+ # allow IPKernelApp.instance():
+ IPKernelApp._instance = app
+
app.init_connection_file()
# relevant contents of init_sockets:

0 comments on commit 64f2f8d

Please sign in to comment.