# Schedule automatic space restart for gradio app

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fschedule-automatic-space-restart-for-gradio-app%2F103028%3E%5C
**Category:** Beginners\
**Created:** [August 19, 2024, 6:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fschedule-automatic-space-restart-for-gradio-app%2F103028 "2024-08-19T18:42:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![drkvcsstvn](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/drkvcsstvn/32/46032_2.png) [@drkvcsstvn](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdrkvcsstvn)%5C
**Post date:** [August 19, 2024, 6:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fschedule-automatic-space-restart-for-gradio-app%2F103028%2F1 "2024-08-19T18:42:39Z")

</div>

Hi!

I wish to schedule an automatic daily restart of my hugging face space where I host a gradio app. Is it possible to do that? I have created a user access token with permission to write for this purpose and I set up the scheduler within the gradio app as I have been instructed by chatgpt.  
I was searching for similar questions I couldn’t find one, if this topic already exists sorry for the repetition.

import gradio as gr  
import threading  
import time  
import schedule  
import requests  
from datetime import datetime

current\_date = datetime.now().strftime(“%Y-%m-%d %H:%M”)

def restart\_space():  
print(“Restarting the space…”)  
response = requests.get(f"[https://huggingface.co/api/spaces/drkvcsstvn/kenetoszto](https://huggingface.co/api/spaces/drkvcsstvn/kenetoszto)",  
params={},  
headers={“Authorization”:“Bearer HF\_API\_TOKEN”}  
)  
if response.status\_code == 200:  
print(“Space restarted successfully.”)  
else:  
print(f"Failed to restart space: {response.status\_code}, {response.text}")

def schedule\_restart():  
schedule.every(2).minutes.do(restart\_space)

```
while True:
    schedule.run_pending()
    time.sleep(1)

```

def start\_scheduler():  
scheduler\_thread = threading.Thread(target=schedule\_restart, daemon=True)  
scheduler\_thread.start()

def greet(name):  
return f"Hello {name}!"

iface = gr.Interface(fn=greet, inputs=“text”, outputs=“text”,title= f’{current\_date}')

start\_scheduler()  
iface.launch()

---

<div class="post-metadata">

**Author:** ![ZennyKenny](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/zennykenny/32/54628_2.png) [@ZennyKenny](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FZennyKenny)%5C
**Post date:** [October 8, 2025, 3:20am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fschedule-automatic-space-restart-for-gradio-app%2F103028%2F2 "2025-10-08T03:20:56Z")

</div>

Hi OP, I built a lightweight tool that does accomplishes this because I was running into the same issues: [GitHub - kghamilton89/spaces-scheduler: This is an automatic scheduler to restart your Hugging Face Space according to a cron job schedule.](https://github.com/kghamilton89/spaces-scheduler)
