Skip to content

Commit

Permalink
Upgrade to support jupyter_client 8 (#1778)
Browse files Browse the repository at this point in the history
When upgrading the dependency spec to include v8, some python tests
broke (see #1728). The tests
were failing with a timeout due to indefinitely blocked IO.

This originates in an infinitely-looping notebook and is caused by a
misconfiguration of the client connection. Currently using
`nbclient.NotebookClient` with a `jupyter_client.manager.KernelManager`
results in a deadlock. nbclient doesn't seem aware of this issue because
there is no test covering it. `NotebookClient` uses `AsyncKernelManager`
by default.

So why isn't nbgrader using it? nbgrader uses the NotebookClient via
nbconvert which just realized the same issue. Up until v7.3.1, nbconvert
has been hard-coding the default kernel manager to the sync version.
(see jupyter/nbconvert#1964)

Rather than require nbconvert>=7.3.1, this commit sets our own default
value to the async kernel manager.
  • Loading branch information
shreve committed Jun 15, 2023
1 parent 3177072 commit 6b0ec9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions nbgrader/preprocessors/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from . import NbGraderPreprocessor
from nbconvert.exporters.exporter import ResourcesDict
from nbformat.notebooknode import NotebookNode
from jupyter_client.manager import AsyncKernelManager
from typing import Any, Optional, Tuple


Expand Down Expand Up @@ -67,6 +68,11 @@ class Execute(NbGraderPreprocessor, ExecutePreprocessor):
""")
).tag(config=True)

def __init__(self, *args, **kwargs):
# nbconvert < 7.3.1 used the sync version of this, which doesn't work for us.
kwargs.setdefault('kernel_manager_class', AsyncKernelManager)
super().__init__(*args, **kwargs)

def on_cell_executed(self, **kwargs):
cell = kwargs['cell']
reply = kwargs['execute_reply']
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies = [
"ipywidgets>=7.6",
"Jinja2>=3",
"jsonschema>=3",
"jupyter_client<8",
"jupyter_client<9",
"jupyter_server>=1.12,<2",
"jupyterlab<4",
"jupyterlab_server",
Expand Down

0 comments on commit 6b0ec9f

Please sign in to comment.