Conversation
execute_notebook(cwd=...) set the working directory via a process-global
os.chdir context manager wrapping the whole engine run, so concurrent
executions with different cwd raced on the single process working directory
and a kernel could launch in the wrong directory.
Thread cwd through execute_notebook_with_engine to PapermillNotebookClient,
which passes it to nbclient as resources={'metadata': {'path': cwd}} so the
kernel starts in cwd without mutating the papermill process. The public
execute_notebook(cwd=...) signature is unchanged. Fixes nteract#473.
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.
Bug
execute_notebook(cwd=...)sets the working directory withutils.chdir, a process-globalos.chdircontext manager wrapping the whole engine run. Concurrent executions with differentcwdrace on the single process working directory, so a kernel can launch in another run's directory. See #473.Fix
Drop the global
chdirinexecute.pyand threadcwdthroughexecute_notebook_with_enginetoPapermillNotebookClient, which passes it to nbclient asresources={'metadata': {'path': cwd}}. The kernel starts incwdwithout mutating the papermill process. This is the approach endorsed in the #473 thread. The publicexecute_notebook(cwd=...)signature is unchanged.Verification
Added
test_concurrent_cwd_isolation: two concurrent runs with differentcwd, held atnotebook_startwith athreading.Barrierto force the interleave. Fails onmain(kernels launch in the wrong dir), passes with this change. ExistingTestCWDand thetest_engines/test_clientwrap/test_utilssuites pass.ruff checkandruff formatclean.