Spaces:
Sleeping
Sleeping
feat(runtime): add lightweight self-ping keepalive thread to prevent idle shutdowns
Browse files
app.py
CHANGED
@@ -847,9 +847,23 @@ if __name__ == "__main__":
|
|
847 |
"show_error": True, # Show detailed errors for debugging
|
848 |
"quiet": False, # Show startup messages
|
849 |
"show_api": True, # Enable API documentation
|
850 |
-
"ssr_mode": False
|
851 |
-
"server_kwargs": {"timeout_keep_alive": 120}
|
852 |
}
|
853 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
854 |
# Enable queue for gradio_client compatibility
|
855 |
demo.queue().launch(**launch_kwargs) # ✅ required for gradio_client to work
|
|
|
847 |
"show_error": True, # Show detailed errors for debugging
|
848 |
"quiet": False, # Show startup messages
|
849 |
"show_api": True, # Enable API documentation
|
850 |
+
"ssr_mode": False # Disable experimental SSR in Docker env
|
|
|
851 |
}
|
852 |
|
853 |
+
# Lightweight keepalive (self-ping) to avoid idle shutdowns
|
854 |
+
try:
|
855 |
+
import threading, time, requests
|
856 |
+
def _keepalive():
|
857 |
+
url = "http://127.0.0.1:7860/"
|
858 |
+
while True:
|
859 |
+
try:
|
860 |
+
requests.get(url, timeout=3)
|
861 |
+
except Exception:
|
862 |
+
pass
|
863 |
+
time.sleep(60)
|
864 |
+
threading.Thread(target=_keepalive, daemon=True).start()
|
865 |
+
except Exception:
|
866 |
+
pass
|
867 |
+
|
868 |
# Enable queue for gradio_client compatibility
|
869 |
demo.queue().launch(**launch_kwargs) # ✅ required for gradio_client to work
|