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

Support MultiKernelManager #51

Merged
merged 4 commits into from
May 14, 2020
Merged
Changes from 3 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
22 changes: 18 additions & 4 deletions nbclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,25 +363,39 @@ async def async_start_new_kernel_client(self, **kwargs):
-------
kc : KernelClient
Kernel client as created by the kernel manager `km`.
kernel_id : string-ized version 4 uuid
The id of the started kernel.
"""
resource_path = self.resources.get('metadata', {}).get('path') or None
if resource_path and 'cwd' not in kwargs:
kwargs["cwd"] = resource_path

if self.km.ipykernel and self.ipython_hist_file:
if hasattr(self.km, 'ipykernel') and self.km.ipykernel and self.ipython_hist_file:
self.extra_arguments += ['--HistoryManager.hist_file={}'.format(self.ipython_hist_file)]

await ensure_async(self.km.start_kernel(extra_arguments=self.extra_arguments, **kwargs))
kernel_id = await ensure_async(self.km.start_kernel(extra_arguments=self.extra_arguments,
**kwargs))

self.kc = self.km.client()
# if self.km is not a KernelManager, it's probably a MultiKernelManager
try:
self.km.client
km = self.km
except AttributeError:
try:
km = self.km.get_kernel(kernel_id)
except AttributeError:
raise AttributeError('self.km={} has no client() or get_kernel() method, '
'what is this?'.format(self.km))

self.kc = km.client()
await ensure_async(self.kc.start_channels())
try:
await ensure_async(self.kc.wait_for_ready(timeout=self.startup_timeout))
except RuntimeError:
await self._async_cleanup_kernel()
raise
self.kc.allow_stdin = False
return self.kc
return self.kc, kernel_id

start_new_kernel_client = run_sync(async_start_new_kernel_client)

Expand Down