Current recommended way to deal with restarted Streamlit sessions, for both recovering the session state and continuing calculations

Open
#9,031 8 comments 11 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
python, streamlit
Domain
backend

Research direction

No files, tests, or entry points are named. Start by reviewing Streamlit's session-state behavior and the existing discussion, then separate the requested recovery of state from persistence of long-running jobs. Done would require a clearly scoped, supported approach for both restart scenarios, including behavior for large in-memory data and ongoing computations.

Written by the indexing model from the issue text.

Description

feature:st.session_state type:enhancement
Checklist
  • I have searched the existing issues for similar feature requests.
  • I added a descriptive title and summary to this issue.
Summary

Background:

Unfortunately the platform where we are primarily deploying Streamlit, Palantir Foundry Code Workspaces, randomly restarts Streamlit sessions. It seems they are unable or unwilling to fix this, which is probably the right way to solve the problem, but I am posting here in case others have similar issues, as this could be a more general topic.

If you run a Jupyter notebook in say JupyterLab and then restart the browser, you see in the console that Jupyter reconnects to the session and everything is preserved nicely.

However, we all know that when Streamlit is restarted (and I personally think Streamlit could be utilized as a more user-friendly Jupyter notebook), nothing is preserved.

We have partially combatted the problem by allowing the user to manually save the session state, but if our users forget, then their work since their last save is lost. Note a consideration at least in our case is that we are performing sometimes complex analyses on large datasets, so at times we have 10-15 GB of data in the session state and are running hours-long computations using multiple cores. Each manual save can therefore take a significant amount of time (~a minute).

Questions:

  1. What is Streamlit's current recommended way to continuously save the session state so that if the session is randomly restarted, all is recovered. This has to be a fast process since again we often have large datasets in memory.
  2. What is Streamlit's current recommended way to persist jobs being run by Streamlit instead of them getting killed if the session is restarted?

Thanks so much in advance for your help!

Why?

No response

How?

No response

Additional Context

No response

Dominant language
Python
Stars
45.8k
Forks
4.4k
Avg merge
21h 22m
Merged PRs (30d)
316

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from streamlit/streamlit

All issues in streamlit/streamlit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.