-
Notifications
You must be signed in to change notification settings - Fork 142
Ensure netrc file is properly flushed and synced #1146
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
Merged
Merged
Conversation
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
Added explicit flush and fsync calls after writing to the netrc file to ensure data is written to disk. Also simplified file creation logic when the file does not exist.
Zeyi-Lin
approved these changes
Jul 5, 2025
Introduced a flush_and_sync function to ensure file contents are written to disk, handling OSError gracefully if fsync is unsupported. Refactored save_key and DataStore to use this approach, and added unit tests for the new utility.
Replaced manual file creation with Path.touch() from pathlib when ensuring the netrc file exists in save_key. This simplifies file creation and improves code readability.
The flush_and_sync function was removed from package.py, and its logic was inlined directly into save_key. Corresponding unit tests for flush_and_sync were also deleted to reflect this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that credentials and datastore writes are durably synced to disk and refactors related file creation logic.
- Simplified
.netrc
file creation usingPath.touch()
- Added
flush()
andfsync()
calls (with OSError handling) after writing to the netrc and datastore files - Updated import of
MetricInfo
,ColumnInfo
, andRuntimeInfo
in the porter package init
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
File | Description |
---|---|
swanlab/package.py | Simplified netrc file creation and added explicit flush/fsync after writing |
swanlab/data/porter/datastore.py | Wrapped datastore flush() /fsync() calls in try-except to ignore OSError |
swanlab/data/porter/init.py | Removed swankit.callback import and re-imported types from swanlab.toolkit |
Comments suppressed due to low confidence (1)
swanlab/data/porter/datastore.py:232
- Add a test to simulate
fsync()
raisingOSError
to verify that the exception is handled as expected.
self._fp.flush()
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.
Added explicit flush and fsync calls after writing to the netrc file to ensure data is written to disk. Also simplified file creation logic when the file does not exist.
这应该能解决单测偶尔报错的问题