Skip to main content

Entrypoints and Hot Reload

Hot reload is a development technique that allows your application to automatically update when it detects changes in the source code. This is especially useful during development to speed up the iteration process, since you can edit directly your files from MINEO.

For Development vs Production​

warning

Hot reload configurations are primarily designed for development environments. In production, it's recommended to use standard entrypoints without automatic reload for better stability and performance.

Two rules for every framework​

  • Poll for changes. The project folder is a network volume, so the operating system does not report file changes. Without polling, the app never reloads.
  • Watch code only. A watcher on every file restarts the app each time it writes its own data (a SQLite file, uploads, logs).

The commands below follow both rules.

Streamlit: Native Hot Reload​

Streamlit includes its own efficient hot reload system that doesn't require additional tools:

# For development (with native hot reload)
pip install -q --no-cache-dir streamlit && streamlit run app.py --server.port 8000 --server.address 0.0.0.0 --server.runOnSave=true --server.fileWatcherType=poll

# For production (without hot reload)
pip install -q --no-cache-dir streamlit && streamlit run app.py --server.port 8000 --server.address 0.0.0.0

Advantages of Streamlit's native approach:

  • Faster and more efficient
  • Better framework integration
  • Lower resource consumption

FastAPI: uvicorn Reload​

uvicorn has its own reload, which watches .py files only. WATCHFILES_FORCE_POLLING=true makes it poll:

# For development (with hot reload)
pip install -q --no-cache-dir fastapi uvicorn watchfiles && WATCHFILES_FORCE_POLLING=true uvicorn main:app --reload --host 0.0.0.0 --port 8000 --proxy-headers --forwarded-allow-ips='*' --root-path "${MINEO_LIVE_APP_URL_PATH%/}"

# For production (without hot reload)
pip install -q --no-cache-dir fastapi uvicorn && uvicorn main:app --host 0.0.0.0 --port 8000 --proxy-headers --forwarded-allow-ips='*' --root-path "${MINEO_LIVE_APP_URL_PATH%/}"
info

The --proxy-headers --forwarded-allow-ips='*' --root-path "${MINEO_LIVE_APP_URL_PATH%/}" flags tell the app it is served behind MINEO's proxy. Set the prefix here and never as root_path= in the FastAPI() constructor, which would overwrite it.

With --root-path, mounted static files work too, with no wrapper: see Static files and the path prefix.

Other Frameworks: Using Watchfiles​

For Gradio, Dash, or custom applications, use watchfiles. --filter python restarts the app on .py changes only.

Gradio with Hot Reload​

# For development (with watchfiles)
pip install -q --no-cache-dir watchfiles gradio && WATCHFILES_FORCE_POLLING=true watchfiles --filter python "python app.py" .

# For production (without hot reload)
pip install -q --no-cache-dir gradio && python app.py

Custom Application​

# For development (with watchfiles)
pip install -q --no-cache-dir watchfiles && WATCHFILES_FORCE_POLLING=true watchfiles --filter python "python your_custom_app.py" .

# For production (without hot reload)
python your_custom_app.py

Advanced Watchfiles Configuration​

You can customize watchfiles behavior according to your needs:

# Monitor only specific files
WATCHFILES_FORCE_POLLING=true watchfiles "python app.py" app.py utils.py

# Poll less often (default: every 300 ms)
WATCHFILES_FORCE_POLLING=true WATCHFILES_POLL_DELAY_MS=1000 watchfiles --filter python "python app.py" .

# Ignore specific directories
WATCHFILES_FORCE_POLLING=true watchfiles --filter python --ignore-paths "logs,__pycache__" "python app.py" .

Performance Considerations​

  • Development: Use hot reload for fast iteration
  • Production: Disable hot reload for better performance
  • Resources: Watchfiles consumes more CPU than native solutions
  • Stability: In production, avoid automatic restarts that could interrupt service

Best Practices​

  1. During development: Use entrypoints with hot reload
  2. Before production deploy: Switch to standard entrypoints
  3. For Streamlit: Prefer the native solution over watchfiles
  4. Monitor resources: Hot reload can increase CPU usage in environments with many files

Hot reload is a powerful tool for development, but as with any tool, use it consciously according to your application's context.