Skip to content

Bonsai: retry the .blend save in save_project when the file is briefly locked (#9506) - #9507

Open
theoryshaw wants to merge 1 commit into
IfcOpenShell:v0.9.0from
theoryshaw:save_blend_retry_on_lock_9506
Open

theoryshaw wants to merge 1 commit into
IfcOpenShell:v0.9.0from
theoryshaw:save_blend_retry_on_lock_9506

Conversation

@theoryshaw

Copy link
Copy Markdown
Member

Closes #9506.

Problem

bim.save_project also saves the synced .blend. Blender writes <file>.blend@ and then renames it over the .blend. On Windows that rename fails while Dropbox, OneDrive or antivirus briefly holds the file open. The operator then aborts with RuntimeError: Error: Cannot change old file (file saved with @), even though the IFC has already been written.

Fix

  • New helper save_blend_file_with_retries() in project/operator.py tries wm.save_mainfile up to 5 times, 200 ms apart, and prints each failed attempt.
  • If every attempt fails, save_project reports a warning (IFC saved, .blend not saved, plus the error) instead of raising.
  • Behaviour is unchanged when the save succeeds, and the metadata-blend path is untouched.

Verification

Headless Blender 5.2 on Windows. The .blend was locked from another thread with open(path, "rb"), which doesn't share delete, and the helper's source was run straight from this file:

Lock save_version = 0 default (Save Versions on)
none saved first try saved first try
0.5 s saved on attempt 3 saved on attempt 3
3 s returned Cannot change old file (file saved with @), no raise returned Version backup failed (file saved with @), no raise

A raw wm.save_mainfile under the same lock raises the reported error, so the repro matches the bug. The full save_project operator was not run with the add-on enabled; only the helper was exercised.

🤖 Generated with Claude Code

…y locked

Saving the IFC also saves the synced .blend. Blender writes "<file>.blend@"
and renames it over the .blend; on Windows that rename fails while Dropbox,
OneDrive or antivirus has the file open, raising "Cannot change old file
(file saved with @)" and aborting the operator with a traceback even though
the IFC was already written.

Retry the .blend save a few times with a short delay, and if it still fails,
report a warning instead of raising.

Co-Authored-By: Claude Opus 5 <[email protected]>
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.

Bonsai: Save IFC fails with "Cannot change old file (file saved with @)" when the .blend is in a Dropbox/OneDrive folder

1 participant