user6790773
user6790773

Reputation: 11

yappi profiler not working on FastAPI uvicorn threads

Overview

I tried using yappi (version 1.4.0) to profile my python (3.10) server. I am using FastAPI version 0.88.0 and uvicorn version 0.20.0 , And no matter how I try to run multithreaded-profiling I cannot get yappi to capture anything but the _MainThread thread :( .
All of my actual code runs and produces the logs and results I expect, but cannot find a single call to a function/module of my own code in the profiling results.

I have seen this lone thread (https://github.com/sumerc/yappi/issues/98) that does not relate to my problem, and looked over everything in the docs and saw nothing wrong with that I was doing.

As a module:

I tried using yappi as a module like so:

import yappi
import fastapi

app = FastAPI()
app.include_router(...)

...  # Send out a few requests, see logs of the requests being handled by my code

yappi.start()  # 'profile_threads=True' default value
uvicorn.run("main:app")
yappi.stop()

yappi.get_func_stats().print_all()
yappi.get_threads_stats().print_all()

And get only results about the _MainThread.

Using CLI

I also tried using the CLI usage, so I ran the following command: yappi server/main.py
and got the same result.

I KNOW my code runs, but there is not a single mention of it in the profile results :(

Upvotes: 1

Views: 1026

Answers (0)

Related Questions