# run.py # ───────────────────────────────────────────────────────────────────────────── # Use this script to start the server instead of calling uvicorn directly. # # DEVELOPMENT (with hot-reload): python run.py # PRODUCTION (no reload): python run.py --no-reload # # WHY THIS FILE EXISTS: # On Windows, `uvicorn main:app --reload` forks a reloader subprocess that # can reset the asyncio event loop policy before our app code runs. # Playwright needs ProactorEventLoop to spawn the Chromium browser process. # Setting the policy HERE — before uvicorn is even imported — guarantees it # is applied correctly in every process (main + reloader). # ───────────────────────────────────────────────────────────────────────────── import asyncio import sys # ✅ Set BEFORE importing uvicorn or any async library if sys.platform.startswith("win"): asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy()) import uvicorn if __name__ == "__main__": reload = "--no-reload" not in sys.argv uvicorn.run( "main:app", host="127.0.0.1", port=8000, reload=reload, # True by default (hot-reload enabled) )