import os
import sys
import uuid

# Stop Python from running 'blkid' to find the server MAC address in cPanel
uuid.getnode = lambda: 123456789012345
# Crucial: Limit OpenBLAS / OMP / MKL threads to 1 on cPanel CloudLinux shared servers
# This prevents "pthread_create failed: Resource temporarily unavailable" errors on 64-core cPanel hosts
os.environ["OPENBLAS_NUM_THREADS"] = "1"
os.environ["MKL_NUM_THREADS"] = "1"
os.environ["OMP_NUM_THREADS"] = "1"
os.environ["VECLIB_MAXIMUM_THREADS"] = "1"
os.environ["NUMEXPR_NUM_THREADS"] = "1"
os.environ["NUMPY_NUM_THREADS"] = "1"

# Add application directory to sys.path
app_dir = os.path.dirname(__file__)
if app_dir not in sys.path:
    sys.path.insert(0, app_dir)

# Import a2wsgi to bridge FastAPI ASGI to cPanel Passenger WSGI
from a2wsgi import ASGIMiddleware
from app.main import app as fastapi_app

# The WSGI callable expected by cPanel CloudLinux Passenger
application = ASGIMiddleware(fastapi_app)
