Skip to content

Commit 8bb845a

Browse files
authored
Merge pull request #55 from davidbrochart/multikernelmanager
Force client class to be async when kernel manager is MultiKernelManager
2 parents 059c505 + 1b38afc commit 8bb845a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

nbclient/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,9 @@ async def async_start_new_kernel_client(self, **kwargs):
388388
except AttributeError:
389389
raise AttributeError('self.km={} has no client() or get_kernel() method, '
390390
'what is this?'.format(self.km))
391+
# since self.km is a MultiKernelManager, it might not be async
392+
# so let's ensure the client is async
393+
km.client_class = 'jupyter_client.asynchronous.AsyncKernelClient'
391394

392395
self.kc = km.client()
393396
await ensure_async(self.kc.start_channels())

nbclient/tests/test_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import IPython
2121
from traitlets import TraitError
2222
from nbformat import NotebookNode
23+
from jupyter_client.asynchronous import AsyncKernelClient
2324
from jupyter_client import KernelManager, MultiKernelManager
2425
from jupyter_client.kernelspec import KernelSpecManager
2526
from nbconvert.filters import strip_ansi
@@ -424,8 +425,8 @@ def test_startnewkernel_with_multikernelmanager():
424425
kc, kernel_id = executor.start_new_kernel_client()
425426
# a multi kernel manager always gives back an id to the started kernel
426427
assert kernel_id is not None
427-
# prove it initalized client
428-
assert kc is not None
428+
# prove it initalized an async client
429+
assert isinstance(kc, AsyncKernelClient)
429430
# since we are not using the setup_kernel context manager,
430431
# cleanup has to be done manually
431432
kc.shutdown()

0 commit comments

Comments
 (0)