I run FastAPI at PyCharm IDE and it always run 3 workers. I don't know why, but, the last instance created is being accessed on every API call.
Could anyone can help how can I get single running worker?
Code:
import uvicorn
from fastapi import FastAPI
from fastapi.templating import Jinja2Templates
from starlette.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware(CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"])
print(f"main.py with :{app}")
@app.get('/')
def home():
return "Hello"
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=False, log_level="debug", debug=True,
workers=1, limit_concurrency=1, limit_max_requests=1)
Console output:
/Users/user/.pyenv/versions/3.7.10/bin/python /Users/user/github/my-project/backend/main.py main.py with :<fastapi.applications.FastAPI object at 0x102b35d50> INFO: Will watch for changes in these directories: ['/Users/user/github/my-project/backend'] INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit) INFO: Started reloader process [96259] using statreload main.py with :<fastapi.applications.FastAPI object at 0x10daadf50> main.py with :<fastapi.applications.FastAPI object at 0x1106bfe50> INFO: Started server process [96261] INFO: Waiting for application startup. INFO: Application startup complete.