Fix: add __name__ guard for Windows multiprocessing

This commit is contained in:
Lizandro Guarnizo
2026-06-17 15:05:57 -05:00
parent a49a6626d3
commit 307f089d4f
+23 -23
View File
@@ -1,23 +1,23 @@
import subprocess, threading, time, sys, os import subprocess, threading, time, sys, os
from pathlib import Path from pathlib import Path
root = Path(__file__).parent.resolve() root = Path(__file__).parent.resolve()
def pull_loop(): def pull_loop():
while True: while True:
time.sleep(60) time.sleep(60)
try: try:
r = subprocess.run(['git', 'pull'], cwd=root, capture_output=True, text=True, timeout=30) r = subprocess.run(['git', 'pull'], cwd=root, capture_output=True, text=True, timeout=30)
if r.stdout.strip(): if r.stdout.strip():
print(f"[auto] git pull: {r.stdout.strip()}") print(f"[auto] git pull: {r.stdout.strip()}")
subprocess.run([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt'], subprocess.run([sys.executable, '-m', 'pip', 'install', '-q', '-r', 'requirements.txt'],
cwd=root, capture_output=True, timeout=30) cwd=root, capture_output=True, timeout=30)
except Exception as e: except Exception as e:
print(f"[auto] pull error: {e}") print(f"[auto] pull error: {e}")
threading.Thread(target=pull_loop, daemon=True).start() if __name__ == '__main__':
os.chdir(root) threading.Thread(target=pull_loop, daemon=True).start()
sys.path.insert(0, str(root)) os.chdir(root)
sys.path.insert(0, str(root))
import uvicorn, main import uvicorn, main
uvicorn.run('main:app', host='0.0.0.0', port=8080, reload=True) uvicorn.run('main:app', host='0.0.0.0', port=8080, reload=True)