hysts HF staff commited on
Commit
f146d30
1 Parent(s): 5904ab6

Instantiate the background scheduler only on Spaces

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  from apscheduler.schedulers.background import BackgroundScheduler
@@ -567,7 +569,8 @@ with gr.Blocks(css=custom_css) as demo:
567
 
568
 
569
  if __name__ == "__main__":
570
- scheduler = BackgroundScheduler()
571
- scheduler.add_job(restart_space, "interval", seconds=1800)
572
- scheduler.start()
 
573
  demo.queue(default_concurrency_limit=40).launch()
 
1
+ import os
2
+
3
  import gradio as gr
4
  import pandas as pd
5
  from apscheduler.schedulers.background import BackgroundScheduler
 
569
 
570
 
571
  if __name__ == "__main__":
572
+ if os.getenv("SPACE_ID"):
573
+ scheduler = BackgroundScheduler()
574
+ scheduler.add_job(restart_space, "interval", seconds=1800)
575
+ scheduler.start()
576
  demo.queue(default_concurrency_limit=40).launch()