Terminating python script after plotting


I’m plotting stock history for various tickers which streamlit does with no issues. However after the plotting completes, I want the python script to be unblocked. The only way to terminate is to use Ctrl-C but this is manual intervention. I’m calling the python script from a GUI so the gui is hung until doing ctrl-C.

Steps to reproduce

Code snippet:

# This is the GUI script which includes the method 'plot_history_clicked' which calls the command to run streamlit

import pathlib
import pygubu
import quote_hist
import quotes
import ticker
import os

PROJECT_PATH = pathlib.Path(__file__).parent
PROJECT_UI = PROJECT_PATH / "main_gui.ui"

class QuoteApp:
    def __init__(self, master=None):
        self.builder = builder = pygubu.Builder()
        # Main widget
        self.mainwindow = builder.get_object("main_window", master)
        # self.text_box = builder.get_object("text_box")

    def run(self):

    def get_quote_history(self):

    def get_quotes(self):
    def get_ticker_clicked(self):
        ticker_entry = self.builder.get_object("user_ticker_entry")
        ticker_sym = ticker_entry.get().lower()
    def plot_history_clicked(self):
        os.system('streamlit run plot_data_streamlit.py')
    def run(self):
    def close_window(self):
# This is the function in the module 'plot_data_streamlit.py' which plots the data:

def plot_ticker_hist(data: List[Tuple[str, DataFrame]]):
    """plot figures from list of ticker dataframe tuples.
        data (list[Tuple]): list of (ticker, ticker dataframes)
    for tupl in data:
        df = tupl[1]
        df['Date'].astype('datetime64') # date column from dbase is str type
        df.sort_values(by='Date', inplace=True) # database not likely in sorted order
        df = df[['Date','Open', 'Close']] # reduce number of columns
        df = df.melt('Date', var_name='category', value_name='price')
        Shown is the **opening** and **closing** price of **{tupl[0].upper()}**
        chart = alt.Chart(df).mark_line().encode(x=alt.X('Date:T'), y=alt.Y('price:Q'), color=alt.Color("category:N"))
        st.altair_chart(chart, use_container_width=True)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

At the end of the for loop, I would like to have a command which terminates or unblocks the event loop so that python scripts completes and therefore unblocks the main gui.

Actual behavior:

As noted, after streamlit plots the data to the browser, the script remains blocked and therefore blocks the GUI.

Debug info

  • Streamlit version: 1.14.0
  • Python version: 3.10
  • Using PyEnv
  • OS version: Windows 10
  • Browser version: Edge 107.0.1418.62

Requirements file

[tool. Poetry]
name = “get-stocks”
version = “0.1.0”
description = “”
authors = [“xxxxx”]
readme = “README.md”
packages = [{include = “get_stocks”}]

python = “~3.10”
pandas = “^1.5.1”
pandas-datareader = “^0.10.0”
beautifulsoup4 = “^4.11.1”
streamlit = “^1.14.0”
pygubu = “^0.27”


  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.