Spaces:
Paused
Paused
Download pinger.py from mohammed978/hostbot: direct link, hf CLI and curl.
- Browser
- Download file 796 Bytes
-
https://huggingface.co/spaces/mohammed978/hostbot/resolve/main/pinger.py
- Command line
-
hf download hf://spaces/mohammed978/hostbot/pinger.py
-
curl -L -o pinger.py https://huggingface.co/spaces/mohammed978/hostbot/resolve/main/pinger.py
796 Bytes
| import requests | |
| import time | |
| import datetime | |
| import os | |
| LOCAL_PORT = os.environ.get("SERVER_PORT", "7860") | |
| LOCAL_URL = f"http://127.0.0.1:{LOCAL_PORT}/health" | |
| TARGETS = [LOCAL_URL] | |
| def start_pinging(): | |
| print(f"[*] Keep-alive targets: {TARGETS}") | |
| fail_count = 0 | |
| while True: | |
| for url in TARGETS: | |
| try: | |
| r = requests.get(url, timeout=15) | |
| now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") | |
| print(f"[{now}] {url} -> {r.status_code}") | |
| fail_count = 0 | |
| except Exception as e: | |
| fail_count += 1 | |
| print(f"[!] Error: {url} -> {e}") | |
| sleep_time = 180 if fail_count == 0 else 60 | |
| time.sleep(sleep_time) | |
| if __name__ == "__main__": | |
| start_pinging() | |