Skip to content

Keep the hot reload watcher alive when a file vanishes before os.stat - #4171

Open
thejesh23 wants to merge 3 commits into
plotly:devfrom
thejesh23:fix/hot-reload-watcher-vanished-file
Open

thejesh23 wants to merge 3 commits into
plotly:devfrom
thejesh23:fix/hot-reload-watcher-vanished-file

Conversation

@thejesh23

Copy link
Copy Markdown

Fixes #4170.

watch() in dash/_watch.py called os.stat on each listed file with no error handling, so a file that vanished after os.walk listed it, or a dangling symlink such as an Emacs lock file assets/.#style.css, raised FileNotFoundError and ended the watcher thread. Hot reload then stopped for the rest of the session. The watcher now skips a file whose os.stat raises OSError. A watched file that disappears is still reported as deleted, since it is not added to walked.

Test: test_dvhr002 in tests/integration/devtools/test_hot_reload.py starts an app with hot reload, adds a dangling symlink to its assets folder, then edits the CSS and waits for the new style. On dev the style never changes (timeout); with the fix it passes, and test_dvhr001 still passes. Skipped on Windows, where creating a symlink needs extra privileges. pytest tests/unit passes locally on Python 3.14; black, flake8 and pylint are clean on Python 3.10.

Contributor Checklist

  • This PR targets dev (fix or chore) or next (feature, new API, breaking change), see Which branch to target
  • I have broken down my PR scope into the following TODO tasks
    • skip files that os.stat cannot read in the hot reload watcher
    • integration test with a dangling symlink in the assets folder
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md

Generated with Claude Code

@sonarqubecloud

Copy link
Copy Markdown

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.

[BUG] Hot reload stops for the session when the watcher hits a file it cannot stat

1 participant