Title: dev_environment.py: a locked file during symlinking leaves the extension half-linked with no recovery hint · Issue #9239 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: dev_environment.py: a locked file during symlinking leaves the extension half-linked with no recovery hint · Issue #9239 · IfcOpenShell/IfcOpenShell
X Title: dev_environment.py: a locked file during symlinking leaves the extension half-linked with no recovery hint · Issue #9239 · IfcOpenShell/IfcOpenShell
Description: When dev_environment.py fails while replacing a package directory with a symlink, it aborts on a raw traceback and leaves the extension in a partially-linked state that Blender cannot import. Nothing in the output indicates what went wro...
Open Graph Description: When dev_environment.py fails while replacing a package directory with a symlink, it aborts on a raw traceback and leaves the extension in a partially-linked state that Blender cannot import. Nothi...
X Description: When dev_environment.py fails while replacing a package directory with a symlink, it aborts on a raw traceback and leaves the extension in a partially-linked state that Blender cannot import. Nothi...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/9239
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"dev_environment.py: a locked file during symlinking leaves the extension half-linked with no recovery hint","articleBody":"When `dev_environment.py` fails while replacing a package directory with a symlink, it aborts on a raw traceback and leaves the extension in a partially-linked state that Blender cannot import. Nothing in the output indicates what went wrong or that re-running the script fixes it.\n\n### What happened\n\nBlender 4.5, Bonsai installed minutes earlier via offline installation:\n\n```\nSymlinking extension to the git repo...\nLinking ...\\extensions\\user_default\\bonsai\\__init__.py -> ...\\src\\bonsai\\bonsai\\__init__.py.\nLinking ...\\site-packages\\bonsai -> ...\\src\\bonsai\\bonsai.\nLinking ...\\site-packages\\ifcopenshell -> ...\\src\\ifcopenshell-python\\ifcopenshell.\nTraceback (most recent call last):\n File \"...\\dev_environment.py\", line 229, in \u003cmodule>\n main()\n File \"...\\dev_environment.py\", line 192, in main\n shutil.rmtree(path)\n File \"...\\shutil.py\", line 808, in rmtree\n return _rmtree_unsafe(path, onexc)\n File \"...\\shutil.py\", line 636, in _rmtree_unsafe\n onexc(os.unlink, fullname, err)\n File \"...\\shutil.py\", line 634, in _rmtree_unsafe\n os.unlink(fullname)\nPermissionError: [WinError 5] Access is denied: '...\\site-packages\\ifcopenshell\\_ifcopenshell_wrapper.cp311-win_amd64.pyd'\n```\n\n`rmtree` had already deleted all but 10 files of `site-packages/ifcopenshell` before hitting the 54 MB `.pyd`, and the symlink was never created — so `import ifcopenshell` was broken in Blender until the script was run again.\n\nInvestigating afterwards, the lock was transient and already gone: no process had the `.pyd` loaded as a module, Blender was not running, the file was not read-only (`Archive` only), the ACL granted `FullControl`, and opening it exclusively for `ReadWrite` with no sharing succeeded. Re-running the script completed without any intervention. The extension had been installed at 08:39 and the script run immediately after, so an antivirus scan of freshly written native binaries is the likely holder. (Deleting a file held as a mapped image or by a scanner returns `WinError 5`, not the `WinError 32` one might expect.)\n\n### Why this is worth handling\n\nhttps://github.com/IfcOpenShell/IfcOpenShell/blob/v0.8.0/src/bonsai/scripts/dev_environment.py#L175-L187\n\n```python\n for path, dest in symlinks:\n print(f\"Linking {path} -> {dest}.\")\n if path.is_dir():\n if path.is_symlink():\n path.unlink()\n else:\n shutil.rmtree(path)\n```\n\n`rmtree` is only reachable when the target is still a real directory — that is, on the **first** run after installing the extension. Every later run finds a symlink and takes `path.unlink()` instead. So the one branch with no error handling is also the one that always runs while the extension's binaries are newly written and most likely to be held by a scanner. New contributors following the setup instructions hit it under precisely the worst conditions, on their first attempt.\n\n### Suggested changes\n\n1. **Retry `rmtree` on `PermissionError`** with a short backoff, rather than aborting on the first failure. In this case the lock cleared on its own well within a few seconds.\n\n2. **Report the partial state and the remedy.** Wrapping the symlink loop so a failure prints something like:\n\n > Failed while replacing `\u003cpath>`. The extension is now partially linked and Blender will not import it until this completes. This is usually a file lock (Blender running, or an antivirus scanning a fresh install) — re-running this script is safe and will finish the job.\n\n would have made the situation self-explanatory. The recovery genuinely is just \"run it again\", but that is not discoverable from a `shutil` traceback.\n\n3. **Preflight check that Blender is not running.** It was not the cause here, but it is the most common cause of a locked file at this step and is cheap to detect.\n\n4. Minor, while in the area: `rmtree` on Windows also fails on read-only files, which an `onexc` handler that clears the read-only bit and retries would cover.\n\nWorth preserving deliberately: the script copies the `*_wrapper*` binaries into the repo **before** any deletion happens, which is why nothing was actually lost when this aborted. That ordering is load-bearing and could use a comment saying so.\n\nEnvironment: Windows 10, Blender 4.5, Bonsai installed via offline installation (`extensions/user_default/bonsai`). Unrelated to #9227 / #9228, which cover `PACKAGE_PATH` detection in the same script.\n\nHappy to open a PR for 1 and 2 if the approach looks right.\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-08-03T14:01:30Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/9239"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:7fe9b041-6093-a03d-bc11-c1029f38e6bd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A60A:2FE7CE:59AA48:7AA8FF:6B04C782 |
| html-safe-nonce | 5f1523c53e93549ab07d30285163d40a8613bce1e1a0b89a42fa32de2659a2d4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNjBBOjJGRTdDRTo1OUFBNDg6N0FBOEZGOjZCMDRDNzgyIiwidmlzaXRvcl9pZCI6IjMyNjQ5MjgzNzEzMjk0NTI4MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3f2616d9d85f9479975f3b642a4061335af0c181061eddddc3ae5897e196b1ee |
| hovercard-subject-tag | issue:5050638700 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/9239/issue_layout |
| twitter:image | https://opengraph.githubassets.com/85505a4b7aa5c61df08562af5ade88eab63163a247970824a0ad407619aa1a2b/IfcOpenShell/IfcOpenShell/issues/9239 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/85505a4b7aa5c61df08562af5ade88eab63163a247970824a0ad407619aa1a2b/IfcOpenShell/IfcOpenShell/issues/9239 |
| og:image:alt | When dev_environment.py fails while replacing a package directory with a symlink, it aborts on a raw traceback and leaves the extension in a partially-linked state that Blender cannot import. Nothi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | theoryshaw |
| hostname | github.com |
| expected-hostname | github.com |
| None | 85dd75377eb77313206b8fc108bcee6a3a029286d94bf32bf9b4426e4d92e0c4 |
| turbo-cache-control | no-preview |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 0d64fa748a2bab9a5b587a967ac4da1cfa8da6dd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width