Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cyrillkuettel/ae2d8a979e466f0af5b539fa22869ae0 to your computer and use it in GitHub Desktop.
Save cyrillkuettel/ae2d8a979e466f0af5b539fa22869ae0 to your computer and use it in GitHub Desktop.
Get number of threads a uvicorn process using

See how many threads FastAPI is running on

If you have a simple FastAPI application you use uvicorn main:app --reload --port 4681 --host 0.0.0.0 with the following main.py

Simple demo app looks like this:

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}
    
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
    return {"item_id": item_id, "q": q}

and it may show the following information

INFO: Started server process [18983]
INFO: Waiting for application startup.
INFO: Uvicorn running on http://0.0.0.0:4681 (Press CTRL+C to quit)

I use ps -o nlwp 18983 to see how many threads this process (18983) is using.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment