From ea2dc2ecd543442e428bb5589f179169ff0c703f Mon Sep 17 00:00:00 2001 From: "Brian E. Granger" Date: Fri, 11 Jan 2013 11:12:31 -0800 Subject: [PATCH] Allow caller of MultiKernelManager.start_kernel to pass kernel_id. --- IPython/frontend/html/notebook/kernelmanager.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/IPython/frontend/html/notebook/kernelmanager.py b/IPython/frontend/html/notebook/kernelmanager.py index c2516d4d7..f3cee73d5 100644 --- a/IPython/frontend/html/notebook/kernelmanager.py +++ b/IPython/frontend/html/notebook/kernelmanager.py @@ -79,8 +79,14 @@ class MultiKernelManager(LoggingConfigurable): return False def start_kernel(self, **kwargs): - """Start a new kernel.""" - kernel_id = unicode(uuid.uuid4()) + """Start a new kernel. + + The caller can pick a kernel_id by passing one in as a keyword arg, + otherwise one will be picked using a uuid. + """ + kernel_id = kwargs.pop('kernel_id', unicode(uuid.uuid4())) + if kernel_id in self: + raise DuplicateKernelError('Kernel already exists: %s' % kernel_id) # use base KernelManager for each Kernel km = self.kernel_manager_factory(connection_file=os.path.join( self.connection_dir, "kernel-%s.json" % kernel_id),