Skip to main content
src/dashboard/reloader.py · chapter The dashboard and publishing, file 3 · 48 lines · open in the repository

What it does

Keep the dashboard’s own modules current between reruns (decision 0013). Streamlit reruns app.py in the same Python process, and on Streamlit Community Cloud a push updates the files without restarting it. app.py itself is read again, but modules it imported earlier (common.*, hosting.live) stay as they were in memory, so new code calling a new function in them fails until someone reboots the app. refresh() runs at the top of app.py: when any project module’s file has changed since this process last loaded it (or this process has not checked it yet), it reloads all of them, settings first, so none keeps stale values imported from another. This module is imported once per process and never reloaded, so it remembers what it saw.

What is inside

  • PACKAGES · line 19
  • SKIP · line 20: this module, and the app (Streamlit reads it again each run)
  • FIRST · line 21: what the others import from
  • _SEEN · line 22: module name -> file modification time when last (re)loaded
  • _BUSY · line 23: a reload runs module code, which must not start another
  • _mtime(module) · line 26
  • refresh(packages) · line 31: Reload every loaded project module if any of them changed on disk. Returns the names reloaded.

Source

src/dashboard/reloader.py