@mytec: iter2.2 start
This commit is contained in:
@@ -1,29 +1,55 @@
|
||||
"""Entry point for PyInstaller bundle"""
|
||||
print("[RFCP] run_server.py starting...", flush=True)
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Set base path for PyInstaller
|
||||
if getattr(sys, 'frozen', False):
|
||||
os.chdir(os.path.dirname(sys.executable))
|
||||
# Fix uvicorn TTY detection — sys.stdin/stdout/stderr are None when frozen
|
||||
base_dir = os.path.dirname(sys.executable)
|
||||
os.chdir(base_dir)
|
||||
print(f"[RFCP] Frozen mode, base dir: {base_dir}", flush=True)
|
||||
|
||||
# Fix uvicorn TTY detection — redirect None streams to a log file
|
||||
log_path = os.path.join(base_dir, 'rfcp-server.log')
|
||||
log_file = open(log_path, 'w')
|
||||
if sys.stdout is None:
|
||||
sys.stdout = log_file
|
||||
if sys.stderr is None:
|
||||
sys.stderr = log_file
|
||||
if sys.stdin is None:
|
||||
sys.stdin = open(os.devnull, 'r')
|
||||
if sys.stdout is None:
|
||||
sys.stdout = open(os.devnull, 'w')
|
||||
if sys.stderr is None:
|
||||
sys.stderr = open(os.devnull, 'w')
|
||||
print(f"[RFCP] Log file: {log_path}", flush=True)
|
||||
|
||||
print("[RFCP] Importing uvicorn...", flush=True)
|
||||
import uvicorn
|
||||
from app.main import app
|
||||
|
||||
print("[RFCP] Importing app.main...", flush=True)
|
||||
try:
|
||||
from app.main import app
|
||||
print("[RFCP] App imported successfully", flush=True)
|
||||
except Exception as e:
|
||||
print(f"[RFCP] FATAL: Failed to import app: {e}", flush=True)
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == '__main__':
|
||||
host = os.environ.get('RFCP_HOST', '127.0.0.1')
|
||||
port = int(os.environ.get('RFCP_PORT', '8888'))
|
||||
|
||||
uvicorn.run(
|
||||
app,
|
||||
host=host,
|
||||
port=port,
|
||||
log_level='warning',
|
||||
access_log=False,
|
||||
)
|
||||
print(f"[RFCP] Starting uvicorn on {host}:{port}", flush=True)
|
||||
|
||||
try:
|
||||
uvicorn.run(
|
||||
app,
|
||||
host=host,
|
||||
port=port,
|
||||
log_level='warning',
|
||||
access_log=False,
|
||||
)
|
||||
except Exception as e:
|
||||
print(f"[RFCP] FATAL: uvicorn.run failed: {e}", flush=True)
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user