From 79257194a65caa89c9cf501a772a2eb35886403d 2012-06-06 04:27:52 From: MinRK Date: 2012-06-06 04:27:52 Subject: [PATCH] bind_kernel on a bound kernel is a no-op --- diff --git a/IPython/parallel/__init__.py b/IPython/parallel/__init__.py index d265596..22d3b69 100644 --- a/IPython/parallel/__init__.py +++ b/IPython/parallel/__init__.py @@ -20,6 +20,7 @@ import warnings import zmq +from IPython.config.configurable import MultipleInstanceError from IPython.zmq import check_for_zmq if os.name == 'nt': @@ -51,12 +52,23 @@ def bind_kernel(**kwargs): This function returns immediately. """ + from IPython.zmq.ipkernel import IPKernelApp from IPython.parallel.apps.ipengineapp import IPEngineApp + + # first check for IPKernelApp, in which case this should be a no-op + # because there is already a bound kernel + if IPKernelApp.initialized() and isinstance(IPKernelApp._instance, IPKernelApp): + return + if IPEngineApp.initialized(): - app = IPEngineApp.instance() - else: - raise RuntimeError("Must be called from an IPEngineApp instance") + try: + app = IPEngineApp.instance() + except MultipleInstanceError: + pass + else: + return app.bind_kernel(**kwargs) + + raise RuntimeError("bind_kernel be called from an IPEngineApp instance") - return app.bind_kernel(**kwargs)