Play nicer with scripts that spawn children processes
See original GitHub issueSummary
When Streamlit interrupts (and terminates) a script that has spawned children processes, the children processes don’t appear to be properly handled causing the session to hang and ultimately become unusable. The user must refresh the browser page to continue using the app; the administrator must send SIGKILL signals the streamlit process (and its children) when trying to stop the streamlit server.
Steps to reproduce
Create a script using with muiltiprocessing.pool.Pool() as pool:
and submit some tasks to the pool that require some time to finish.
Before the pool has been closed and joined, click Stop or Rerun for the script.
Notice the session is now hung and the children processes that persist.
Expected behavior:
Streamlit should probably send some king of a signal to the script so it can attempt to terminate itself before Streamlit kills it.
Actual behavior:
Session is seemingly corrupted and children processes are orphaned.
Is this a regression?
No
Debug info
- Streamlit version: 0.53.0
- Python version: 3.8.1
- Using Conda? PipEnv? PyEnv? Pex? Just a normal virtual environment from python -m venv
- OS version: CentOS Linux 7
- Browser version: Firefox 72.0.1
Additional information
More here discuss.streamlit.io
Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.
If you’d like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:6 (1 by maintainers)
Top GitHub Comments
I wonder if we could add something like
st.signal_handler(handler_function)
that would allow app scripts to register a “Streamlit signal handler” to be called when the script is being terminated early, so that multi-threaded or multi-process Streamlit apps can handle cleanup tasks properly.I’m also facing this. Streamlit is unable to handle child procs.
Streamlit process cannot be killed with SIGTERM (just prints
stopping ...
) and I see child procs spinning at 100% cpu even if no browser is open.system.exit()
orquit
won’t do, only SIGKILL will return to shell