Fix: Prevent Flask hot reload from hanging due to early thread startup #7966
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Prevent Flask hot reload from hanging due to early thread startup
What problem does this PR solve?
When running the Flask server with
use_reloader=True
(enabled during debug mode), modifying a Python source file would trigger a reload detection (Detected change in ...
), but the application would hang instead of restarting cleanly.This was caused by the
update_progress
background thread being started too early, often within the main module scope.This issue was reported in #7498.
Type of change
Summary of changes:
update_progress
launch in athreading.Timer
with delay to avoid premature thread execution.daemon=True
to avoid blocking process exit.WERKZEUG_RUN_MAIN
environment check to ensure background threads only run in the reloader child process (the actual Flask app).debug=False
).