Server shutdown fails to exit while processing infinite loop
See original GitHub issueSummary
Python process does not exit when shutting down the server while processing an infinite loop in a script
Steps to reproduce
Code snippet: (using a recent SessionState prototype, before I fixed the implementation)
import streamlit as st
state = st.get_state()
st.write("printed something")
st.write("foobar" in state) # this line infinite looped before I fixed the implementation
If applicable, please provide the steps we should take to reproduce the bug:
- Run the above snippet against the previous state prototype (I ran the react server as a separate process from the dev install of that commit, rather than running them together via a wheel, don’t know if that affects this)
- C-c in the shell running the python server
Expected behavior:
Python server stops, process exits and control returns to my shell
Actual behavior:
Logs indicate server goes into the STOPPING state and then almost immediately the STOPPED state, but after 20 seconds it still has not exited the process. Sending SIGTERM repeatedly afterwards fails to cause the process to exit, and SIGKILL was required to regain control.
Is this a regression?
Unknown
Debug info
- Streamlit version: Session state prototype, as linked above, development install
- Python version: 3.8.6
- Using Conda? PipEnv? PyEnv? Pex?: Pipenv
- OS version: Arch Linux
- Shell version: Zsh 5.8
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Stopping an infinite loop on a remote server PHP
You might want to contact your hosting service and ask them to kill your script. Most likely you don't have execute-access or ssh-access....
Read more >What happens if I run an infinite loop on a server? - Quora
In C, and infinite loop is easy : · That is an infinite loop - and it will run until you (or your...
Read more >Bug #551130 “[SRU] infinite loop in /etc/init/mysql.conf if mysq...”
The file /etc/init/mysql.conf will go into an infinite loop waiting for mysqladmin to succeed if the mysqld daemon is failing.
Read more >Stopping and Correcting Endless Loops in Business Processes
Diagnosing The Problem. From Websphere Process Server Version 7.0.0.2 onwards the following warning can be used to help identify where the loop ......
Read more >Bash Infinite Loop Examples - nixCraft
How do I write an infinite loop in Bash script under Linux or UNIX like operating ... Using case statement to exit infinite...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@robertmartin8 I’ve been thinking about this, and I came up with an idea on my personal time that might help. Essentially, I implemented a custom component that auto re-runs the app. This avoids the need of an infinite loop in the script. This improves the developer experience (shutting down while an infinite loop is running) while easing resources on the server with a tiny tradeoff from the user.
https://github.com/kmcgrady/streamlit-autorefresh
Here’s a trivial example.
Your use case suggests this could work and may even simplify your work. Given the code structure, the new script would be:
The only use case that I think this would hurt is one with complex UI implemented before the infinite loop. That being said, proper caching could solve that challenge.
Let me know if it helps or not. It’s a simple component so feedback is appreciated.
@schaumb That approach seems promising. Could you open a PR for it?