Function keeps running over and over again

Iโ€™m running the app locally as follows:

Streamlit 1.28.2
Python 3.12

I have the following single file that I run streamlit run I want GetToken() to run once, but it runs over and over again.

import toml
import requests
import json
import pandas as pd
import streamlit as st

accounts = st.secrets["accounts"]
initial_token = st.secrets["refresh_token"]
url = st.secrets["api_server"]

def getToken():
    # get a new refresh token and populate variables

    r = json.loads(

    # url = r["api_server"]
    access_token = r["access_token"]
    refresh_token = r["refresh_token"]
    header = {"Authorization": f"Bearer {refresh_token}"}

    data = toml.load(".streamlit/secrets.toml")
    data["refresh_token"] = refresh_token
    data["access_token"] = access_token
    data["header"] = header
    # data["api_server"] = url
    f = open(".streamlit/secrets.toml", "w")
    toml.dump(data, f)


if __name__ == "__main__":

Deactivate โ€œRun on savingโ€ in the settings.

Try use

def main():

if __name__ == "__main__":

Thanks. This was the solution. I didnโ€™t realize that the runOnSave is triggered even when a change is done to files in the .streamlit dir. I assumed it would only run on files in the root dir.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.