mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-04 02:46:33 +00:00
**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](https://github.com/infiniflow/ragflow/issues/7498). ### Type of change - [x] 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`). --------- Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>