question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Play nicer with scripts that spawn children processes

See original GitHub issue

Summary

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:open
  • Created 4 years ago
  • Reactions:8
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tconklingcommented, Jan 29, 2020

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.

0reactions
arkanoid87commented, Apr 12, 2022

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() or quit won’t do, only SIGKILL will return to shell

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to spawn parallel child processes on a multi-processor ...
I have a server with 64 processors, so want to spawn up to 64 child processes of this second Python script. The child...
Read more >
How JavaScript works: building a child process in Node.js
This is one method that can scale your application server. Other ways include the spawn() , exec() , and execFile() . Even if...
Read more >
The subprocess Module: Wrapping Programs With Python
If you've ever wanted to simplify your command-line scripting or use ... The Python subprocess module is for launching child processes.
Read more >
Pexpect Documentation - Read the Docs
Pexpect makes Python a better tool for controlling other applications. ... Pexpect allows your script to spawn a child application.
Read more >
Spawning Actors | Unreal Engine 4.27 Documentation
bDeferConstruction. A bool that determines whether the construction script will be run. If true , the construction script will not be run on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found