Python / Uvicorn Fundamentals Interview Questions
How do you configure Uvicorn's timeout settings?
Uvicorn provides several timeout parameters that control how long the server waits for client activity and worker health before taking action.
| Setting | Default | Purpose |
|---|---|---|
| --timeout-keep-alive | 5s | Seconds to wait for a new request on a keep-alive connection before closing |
| --timeout-notify | 30s | Seconds to notify worker processes during graceful shutdown before sending SIGKILL |
| --timeout-graceful-shutdown | None (no limit) | Maximum seconds for the server to wait for ongoing requests to complete during shutdown |
| --timeout-worker-healthcheck | 5s | Seconds to wait for a worker to respond to a health check |
# Configure keep-alive timeout (how long idle connections stay open) uvicorn main:app --timeout-keep-alive 10 # Graceful shutdown timeout (force-kill after N seconds if requests don't finish) uvicorn main:app --timeout-graceful-shutdown 30 # Worker health check timeout uvicorn main:app --timeout-worker-healthcheck 10 # Programmatic: uvicorn.run( "main:app", timeout_keep_alive=10, timeout_graceful_shutdown=30, ) # Gunicorn has its own timeout settings that overlay Uvicorn's: # gunicorn --timeout 120 (worker timeout for handling a request) # gunicorn --graceful-timeout 30 (graceful shutdown window)
Keep-alive tuning: the default 5-second keep-alive timeout is appropriate for most use cases. For high-throughput APIs with many short-lived requests, a lower value (2-3s) reduces idle connections. For APIs with slower clients or large payloads, a higher value reduces connection setup overhead.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
