Repository navigation
Keep IPython history in memory and add --nbval-kernel-startup-retries - #233
Open
julian-belina wants to merge 3 commits into
Open
julian-belina wants to merge 3 commits into
julian-belina wants to merge 3 commits into
Conversation
pytest 9 has a built-in pytest_report_teststatus implementation (in
_pytest/subtests.py) that takes config. NbdimeReporter calls the hook
without it, so pluggy raises
HookCallError: hook call must provide argument 'config'
and a run with --nbdime ends with an internal error. This is why
test_nbdime fails with pytest 9.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nbval starts each notebook's kernel once. If that kernel dies or does not reply within the startup timeout, every cell of the notebook errors. With --nbval-kernel-startup-retries=N, nbval shuts the failed kernel down and starts a new one, up to N times, and raises the last error if all of them fail. Each new kernel gets new ports, so a port that another process took in the meantime does not stop it. The default of 0 keeps the current behaviour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kernels that start at the same time, e.g. the first kernels of a
pytest-xdist session in a fresh home directory, all create and open the
profile's history.sqlite. IPython takes the locked database for a
corrupt one and renames it, and a kernel dies when another kernel has
renamed the file first:
File "IPython/core/history.py", line 105, in catch_corrupt_db
self.hist_file.rename(newpath)
FileNotFoundError: [Errno 2] No such file or directory
Start IPython kernels with --HistoryManager.hist_file=:memory:, as
nbclient does by default. nbval runs cells with store_history=False, so
the file never held anything from the tests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
julian-belina
force-pushed
the
kernel-startup-retries
branch
from
November 3, 2026 01:54
4838841 to
7c09b91
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #232.
This PR builds on #234 and includes its commit, so that CI passes here. Merging #234 first keeps the diff of this PR to its own two commits.
Kernels that nbval starts at the same time, e.g. under pytest-xdist, can die before they reply to
kernel_info, and every cell of the notebook then errors. #232 has tracebacks for the two causes. This PR addresses both.Keep the history of IPython kernels in memory. nbval now starts IPython kernels with
--HistoryManager.hist_file=:memory:, as nbclient does by default. Otherwise every kernel creates and opens the profile'shistory.sqlite. IPython takes a database that another kernel has locked for a corrupt one and renames it, and a kernel dies when another kernel has renamed the file first. nbval runs cells withstore_history=False, so the file never held anything from the tests. The argument is passed for the kernel names that jupyter_client treats as IPython (KernelManager.ipykernel, which nbclient uses too) and for:nbval-parent-env.--nbval-kernel-startup-retries=N. If a kernel dies or does not reply within--nbval-kernel-startup-timeout, nbval shuts it down and starts a new one, up to N times, and raises the last error if all of them fail. Each newKernelManagerpicks new ports, which gets around a port that another process took before the kernel could bind it. The default is 0, so nothing changes unless the option is set.Tests (
tests/test_kernel_startup.py):hist_fileis:memory:.I ran the test suite as
dodo.py testdoes on Windows with Python 3.12, pytest 9.2, jupyter_client 8.10 and ipykernel 7.4. It gives the same results as master, apart from the 3 new tests, which pass. Four tests fail on master there too:test_nbdime, which #234 fixes, and three LaTeX and stream samples, which pass on AppVeyor.The two changes are independent, so I can split them into two PRs if you prefer.
🤖 Generated with Claude Code