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

⚠️ Important: 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.

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 --no-cache-dir streamlit && streamlit run app.py --server.port 8000 --server.runOnSave=true --server.fileWatcherType=poll

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

Advantages of Streamlit's native approach:

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

Other Frameworks: Using Watchfiles

For frameworks like FastAPI, Gradio, or custom applications that don't have built-in hot reload, you can use watchfiles:

FastAPI with Hot Reload

# For development (with watchfiles)
pip install --no-cache-dir watchfiles fastapi uvicorn && watchfiles "uvicorn main:app --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 --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 make redirects, HTTPS, and /docs work behind MINEO's proxy. See FastAPI for the full explanation. Keep your code as plain app = FastAPI() — don't set root_path= there.

Gradio with Hot Reload

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

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

Custom Application

# For development (with watchfiles)
pip install --no-cache-dir watchfiles && watchfiles "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 "python app.py" app.py utils.py

# With custom interval (default: 500ms)
watchfiles --interval 1000 "python app.py" .

# Ignore specific directories
watchfiles --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.