Skip to content

Fix: Prevent Flask hot reload from hanging due to early thread startup #7966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2025

Conversation

KraHsu
Copy link
Contributor

@KraHsu KraHsu commented May 30, 2025

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

  • Bug Fix (non-breaking change which fixes an issue)

Summary of changes:

  • Wrapped update_progress launch in a threading.Timer with delay to avoid premature thread execution.
  • Marked thread as daemon=True to avoid blocking process exit.
  • Added WERKZEUG_RUN_MAIN environment check to ensure background threads only run in the reloader child process (the actual Flask app).
  • Retained original behavior in production mode (debug=False).

Fix: Prevent Flask hot reload from hanging due to early thread startup
@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels May 30, 2025
@KevinHuSh KevinHuSh added ci Continue Integration and removed ci Continue Integration labels May 30, 2025
@KevinHuSh KevinHuSh merged commit 241fdf2 into infiniflow:main May 30, 2025
1 check passed
@KraHsu KraHsu deleted the KraHsu-patch-1 branch May 30, 2025 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants