webmentai / run.py
subhandev1
Deploy FastAPI backend with Brevo email, contact form, and SEO reports
f5e7f79
Raw
History Blame Contribute Delete
1.5 kB
# 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)
)