# How do I rerun a streamlit script?

**URL:** <https://discuss.streamlit.io/t/how-do-i-rerun-a-streamlit-script/9515>\
**Category:** Using Streamlit\
**Created:** [February 4, 2021, 4:37pm UTC](https://discuss.streamlit.io/t/how-do-i-rerun-a-streamlit-script/9515 "2021-02-04T16:37:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anansrivastava](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/anansrivastava/32/3476_2.png) [@anansrivastava](https://discuss.streamlit.io/u/anansrivastava)\
**Post date:** [February 4, 2021, 4:37pm UTC](https://discuss.streamlit.io/t/how-do-i-rerun-a-streamlit-script/9515/1 "2021-02-04T16:37:47Z")

</div>

How can I re-run a script every x hours?  
My command - streamlit run main.py

My attempts - run\_script.py

```
import schedule
import time
import os

# run command
def job():
    os.system('streamlit run ../main.py')

# schedule everyday
schedule.every(10).seconds.do(job)
print('run')
# keep running
while 1:
    schedule.run_pending()

    time.sleep(1)

```

This script runs fine but doesn’t update new entries from the database. I have to manually stop and start to see the changes.

Second attempt

> [@Button to clear cache and rerun](https://discuss.streamlit.io/t/button-to-clear-cache-and-rerun/3928):
>
> Is there a way to create a button on my page that does the following (a) clear cache and (b) rerun?

> <https://gist.github.com/tvst/ef477845ac86962fa4c92ec6a72bb5bd>

Not sure how to use this script.

Folder structure

```
main folder
    scheduler folder
         run_script.py
    main.py

```

Wish to trigger main.py from the run\_script.py. Thank you.

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [February 8, 2021, 4:20pm UTC](https://discuss.streamlit.io/t/how-do-i-rerun-a-streamlit-script/9515/2 "2021-02-08T16:20:30Z")

</div>

Hi @anansrivastava -

This seems like your process would be better written as a shell script, instead of a Streamlit app. Meaning, if there’s no user, why use a user-interface library?

What is the higher level goal you are trying to accomplish?

Best,  
Randy

---

<div class="post-metadata">

**Author:** ![randyzwitch](https://sea2.discourse-cdn.com/streamlit/user_avatar/discuss.streamlit.io/randyzwitch/32/58772_2.png) [@randyzwitch](https://discuss.streamlit.io/u/randyzwitch)\
**Post date:** [May 13, 2022, 8:43pm UTC](https://discuss.streamlit.io/t/how-do-i-rerun-a-streamlit-script/9515/3 "2022-05-13T20:43:20Z")

</div>


