Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,897 Bytes
7a6c881 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#!/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() |