Spaces:
Build error
Build error
#!/usr/bin/env python3 | |
import http.client | |
import time | |
import sys | |
def check_server_health(): | |
"""Check if the server is running and responding to requests.""" | |
conn = http.client.HTTPConnection("localhost", 7860) | |
try: | |
conn.request("GET", "/") | |
response = conn.getresponse() | |
return response.status == 200 | |
except Exception as e: | |
print(f"Error checking server health: {e}") | |
return False | |
finally: | |
conn.close() | |
# Wait for the server to start (max 30 seconds) | |
max_attempts = 30 | |
for attempt in range(max_attempts): | |
if check_server_health(): | |
print("Server is healthy!") | |
sys.exit(0) | |
print(f"Waiting for server to start... ({attempt+1}/{max_attempts})") | |
time.sleep(1) | |
print("Server failed to start within the expected time.") | |
sys.exit(1) |