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

Handle client 8 support #253

Merged
merged 6 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 0 additions & 6 deletions nbclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,6 @@ def create_kernel_manager(self) -> KernelManager:
else:
self.km = self.kernel_manager_class(kernel_name=self.kernel_name, config=self.config)
assert self.km is not None

# If the current kernel manager is still using the default (synchronous) KernelClient class,
# switch to the async version since that's what NBClient prefers.
if self.km.client_class == 'jupyter_client.client.KernelClient':
self.km.client_class = 'jupyter_client.asynchronous.AsyncKernelClient'

return self.km

async def _async_cleanup_kernel(self) -> None:
Expand Down
16 changes: 14 additions & 2 deletions nbclient/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,17 @@ def timeout_func(source):
with pytest.raises(TimeoutError):
run_notebook(filename, dict(timeout_func=timeout_func), res)

def test_sync_kernel_manager(self):
nb = nbformat.v4.new_notebook() # Certainly has no language_info.
executor = NotebookClient(nb, kernel_name="python", kernel_manager_class=KernelManager)
nb = executor.execute()
assert 'language_info' in nb.metadata
with executor.setup_kernel():
assert executor.kc is not None
info_msg = executor.wait_for_reply(executor.kc.kernel_info())
assert info_msg is not None
assert 'name' in info_msg["content"]["language_info"]

def test_kernel_death_after_timeout(self):
"""Check that an error is raised when the kernel is_alive is false after a cell timed out"""
filename = os.path.join(current_dir, 'files', 'Interrupt.ipynb')
Expand All @@ -653,9 +664,10 @@ async def is_alive():
return False

km.is_alive = is_alive
# Will be a RuntimeError or subclass DeadKernelError depending
# Will be a RuntimeError, TimeoutError, or subclass DeadKernelError
# depending
# on if jupyter_client or nbconvert catches the dead client first
with pytest.raises(RuntimeError):
with pytest.raises((RuntimeError, TimeoutError)):
input_nb, output_nb = executor.execute()

def test_kernel_death_during_execution(self):
Expand Down