Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap setting of kernel_id with method that can then be overridden in … #353

Merged
merged 2 commits into from
Mar 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions jupyter_client/multikernelmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def start_kernel(self, kernel_name=None, **kwargs):
"""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.
otherwise one will be generated using new_kernel_id().

The kernel ID for the newly started kernel is returned.
"""
kernel_id = kwargs.pop('kernel_id', unicode_type(uuid.uuid4()))
kernel_id = kwargs.pop('kernel_id', self.new_kernel_id(**kwargs))
if kernel_id in self:
raise DuplicateKernelError('Kernel already exists: %s' % kernel_id)

Expand Down Expand Up @@ -315,3 +315,12 @@ def connect_hb(self, kernel_id, identity=None):
=======
stream : zmq Socket or ZMQStream
"""

def new_kernel_id(self, **kwargs):
"""
Returns the id to associate with the kernel for this request. Subclasses may override
this method to substitute other sources of kernel ids.
:param kwargs:
:return: string-ized version 4 uuid
"""
return unicode_type(uuid.uuid4())