fix: clean up temp directory in JupyterCodeExecutor.stop()#7436
Open
r266-tech wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: clean up temp directory in JupyterCodeExecutor.stop()#7436r266-tech wants to merge 1 commit intomicrosoft:mainfrom
r266-tech wants to merge 1 commit intomicrosoft:mainfrom
Conversation
JupyterCodeExecutor created a temp directory via tempfile.mkdtemp() when no output_dir was provided, but never cleaned it up in stop(). This was inconsistent with other executors (LocalCommandLineCodeExecutor, DockerCommandLineCodeExecutor, AzureContainerCodeExecutor) which all properly clean up their temp directories. Changes: - Use tempfile.TemporaryDirectory() instead of tempfile.mkdtemp() when output_dir is None (auto-cleanup on context exit) - Add cleanup of self._temp_dir in stop() method - Add tests verifying cleanup behavior for both cases Fixes microsoft#7217
Contributor
|
@r266-tech please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Summary
Fixes #7217
JupyterCodeExecutorcreates a temp directory viatempfile.mkdtemp()when nooutput_diris provided, but never cleans it up instop(). This is inconsistent with every other executor in the codebase (LocalCommandLineCodeExecutor,DockerCommandLineCodeExecutor,AzureContainerCodeExecutor) which all properly clean up their temp directories.Over time, leaked directories and their contents (generated images, HTML files) accumulate on disk.
Changes
tempfile.TemporaryDirectory()instead oftempfile.mkdtemp()whenoutput_dirisNone. This provides automatic cleanup via context manager semantics.stop()method: if_temp_direxists, callcleanup()and set toNone.test_temp_dir_cleanup_on_stop— verifies temp dir is removed afterstop()when nooutput_diris providedtest_explicit_output_dir_not_cleaned_up— verifies explicitly providedoutput_diris preservedPattern consistency
This follows the exact pattern used by
LocalCommandLineCodeExecutor:Testing
output_dir, so behavior is unchanged)