Spaces:
Running
on
Zero
Running
on
Zero
#!/usr/bin/env python3 | |
""" | |
Wrapper script for Tranception app with Zero GPU error handling | |
""" | |
import os | |
import sys | |
import subprocess | |
import time | |
def run_app(disable_zero_gpu=False): | |
"""Run the main app with optional Zero GPU disable""" | |
env = os.environ.copy() | |
if disable_zero_gpu: | |
env['DISABLE_ZERO_GPU'] = 'true' | |
print("Running with Zero GPU disabled") | |
else: | |
print("Attempting to run with Zero GPU support") | |
cmd = [sys.executable, "app.py"] | |
return subprocess.run(cmd, env=env) | |
def main(): | |
"""Main wrapper that handles Zero GPU initialization errors""" | |
max_retries = 3 | |
retry_count = 0 | |
while retry_count < max_retries: | |
try: | |
# First attempt with Zero GPU | |
if retry_count == 0: | |
result = run_app(disable_zero_gpu=False) | |
else: | |
# Subsequent attempts without Zero GPU | |
print(f"Retry {retry_count}: Running without Zero GPU") | |
result = run_app(disable_zero_gpu=True) | |
# Check if the app exited due to Zero GPU error | |
if result.returncode == 1: | |
retry_count += 1 | |
if retry_count < max_retries: | |
print(f"App crashed. Waiting 5 seconds before retry...") | |
time.sleep(5) | |
continue | |
else: | |
# Normal exit or other error | |
break | |
except KeyboardInterrupt: | |
print("\nShutting down...") | |
break | |
except Exception as e: | |
print(f"Unexpected error: {e}") | |
retry_count += 1 | |
if retry_count < max_retries: | |
time.sleep(5) | |
if retry_count >= max_retries: | |
print("Max retries reached. Please check the logs.") | |
sys.exit(1) | |
if __name__ == "__main__": | |
main() |