Spaces:
Runtime error
Runtime error
| # 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) | |
| ) | |