Skip to content

Added Files using tenacity for retrying renaming a directory on a opened filepath.#1826

Closed
spa51273 wants to merge 2 commits intobeeware:mainfrom
spa51273:bugs/win-renamepath-bug
Closed

Added Files using tenacity for retrying renaming a directory on a opened filepath.#1826
spa51273 wants to merge 2 commits intobeeware:mainfrom
spa51273:bugs/win-renamepath-bug

Conversation

@spa51273
Copy link
Copy Markdown
Contributor

@spa51273 spa51273 commented May 21, 2024

PR Checklist:

  • [ x] All new features have been tested
  • All new features have been documented
  • [ x] I have read the CONTRIBUTING.md file
  • [ x] I will abide by the code of conduct

@spa51273 spa51273 marked this pull request as ready for review May 21, 2024 18:36
Copy link
Copy Markdown
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR - the broad structure looks good; I've got some comments inline.

Comment thread pyproject.toml
"tenacity >= 8.0, < 9.0",
"tomli >= 2.0, < 3.0; python_version <= '3.10'",
"tomli_w >= 1.0, < 2.0",
"tomli_w >= 1.0, < 2.0"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comma on the end is intentional.

Suggested change
"tomli_w >= 1.0, < 2.0"
"tomli_w >= 1.0, < 2.0",

def test_rename_path(mock_tools, tmp_path):
def openclose(filepath):
handler = filepath.open(encoding="UTF-8")
time.sleep(1)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sleep needs to be shorter - 1 second is a long time in a test

def openclose(filepath):
handler = filepath.open(encoding="UTF-8")
time.sleep(1)
handler.close()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The close should be in a try:finally to ensure that if other parts of the process fail, the file will still be closed.

rename_thread = threading.Thread(
target=mock_tools.files.path_rename,
args=(tmp_path / "orig-dir-1", tmp_path / "new-dir-1"),
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the rename thread needed? It should be possible to do this inline.

file_access_thread.start()
rename_thread.start()

rename_thread.join()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should join on the file_access_thread to ensure that it cleans up.



@pytest.mark.xfail(
sys.platform == "win32",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little concerned about this being a win32 only error. macOS and Linux won't fail because of a file rename, but they could fail for other reasons - we need to verify the "will eventually fail" path on all platforms.


Windows does not like renaming a dir in a path with an opened file.
"""
old_path.rename(new_path)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a "retry on any error" handler - what happens for predictable failure - e.g., attempting to rename a file that doesn't exist? There are some failures that should be surfaced immediately.

@spa51273
Copy link
Copy Markdown
Contributor Author

Russell / Russell and Malcom,
Thanks so much for all your patience and guidance!

I will address all the above on this PR this weekend or early next week. Hope it's not too late. Work got backlogged for the past 7 days and unfortunately I'll need to catch up with it first...

@rmartin16
Copy link
Copy Markdown
Member

Just FYI: I ended up implementing the File tool in #1871; this will save you some work in this PR but you will first either need to rebase what's here on main or merge main in to update it. Feel free to let us know if you run in to issues or have any questions.

@JohananOppongAmoateng
Copy link
Copy Markdown
Contributor

@spa51273 are you still working on this?

@spa51273
Copy link
Copy Markdown
Contributor Author

spa51273 commented Mar 8, 2026 via email

@mhsmith
Copy link
Copy Markdown
Member

mhsmith commented Mar 9, 2026

Superseded by #2725.

@mhsmith mhsmith closed this Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

On Windows, renaming a directory that was just created can fail with PermissionError: [WinError 5] Access denied

5 participants