Skip to content

Conversation

SAKURA-CAT
Copy link
Member

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.

这应该能解决单测偶尔报错的问题

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.
@SAKURA-CAT SAKURA-CAT requested review from Zeyi-Lin and Copilot July 5, 2025 10:29
@SAKURA-CAT SAKURA-CAT self-assigned this Jul 5, 2025
@SAKURA-CAT SAKURA-CAT added 🐛 bug Something isn't working 💪 enhancement New feature or request labels Jul 5, 2025
Copilot

This comment was marked as outdated.

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.
@SAKURA-CAT SAKURA-CAT requested a review from Copilot July 5, 2025 10:48
Copy link

@Copilot Copilot AI left a 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 using Path.touch()
  • Added flush() and fsync() calls (with OSError handling) after writing to the netrc and datastore files
  • Updated import of MetricInfo, ColumnInfo, and RuntimeInfo 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() raising OSError to verify that the exception is handled as expected.
                self._fp.flush()

@SAKURA-CAT SAKURA-CAT merged commit 75e578f into main Jul 5, 2025
5 checks passed
@SAKURA-CAT SAKURA-CAT deleted the fix/save-key-flush branch July 5, 2025 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working 💪 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants