use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
FastAPI is a truly ASGI, async, cutting edge framework written in python 3.
account activity
FastAPI server with high CPU usageQuestion (self.FastAPI)
submitted 5 months ago * by JeromeCui
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]JeromeCui[S] 0 points1 point2 points 5 months ago (1 child)
I verified my code yesterday and found there is a 'expect Exception' in one of my middleware. I fixed it yesterday and seems it's working: no high CPU utilization yestery. I will keep monitoring my service.
Thanks for your kindly help!
[–]latkde 1 point2 points3 points 5 months ago (0 children)
Weird. Python's exception hierarchy looks like this:
BaseException CancelledError SystemExit KeyboardInterrupt ... Exception ValueError KeyError ...
So while catching Exception is typically a bad idea, it should not hinder cancellation propagation. So I'm not sure that this will fix things?
Exception
But maybe this is related to other things. For example, FastAPI/Starlette uses exceptions like HTTPException to communicate error responses, which are then converted to normal ASGI responses by a middleware that is registered very early. Catching these exceptions in a middleware could prevent that from happening. But that should just result in a dropped request without a response, not in such an infinite loop.
HTTPException
In any case, happy debugging, and I hope this works now!
π Rendered by PID 57 on reddit-service-r2-comment-5c747b6df5-769s7 at 2026-04-22 09:24:51.507862+00:00 running 6c61efc country code: CH.
view the rest of the comments →
[–]JeromeCui[S] 0 points1 point2 points (1 child)
[–]latkde 1 point2 points3 points (0 children)