---
title: "Discussion on \"Why requests.get(timeout=5) can still hang, and how to set a total deadline\" | Hashnode"
description: "Discussion on \"Why requests.get(timeout=5) can still hang, and how to set a total deadline\". If you call an HTTP API from Python with requests and pass timeout=5, a slow server can still keep that call open for much longer than five seconds. This post reproduces it with a small local server a"
url: "https://hashnode.com/posts/why-requests-get-timeout-5-can-still-hang-and-how-to-set-a-total-deadline/6ade99556123af80316ccc42"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Why requests.get(timeout=5) can still hang, and how to set a total deadline](https://tomosu.hashnode.dev/why-requests-get-timeout-5-can-still-hang-and-how-to-set-a-total-deadline?utm_source=hashnode&utm_medium=feed)

If you call an HTTP API from Python with requests and pass timeout=5, a slow server can still keep that call open for much longer than five seconds. This post reproduces it with a small local server a

Oct 26 · 5 min read · tomosu.hashnode.dev  
Read the article

-   [#python](https://hashnode.com/tag/python)
-   [#debugging](https://hashnode.com/tag/debugging)
-   [#backend-development](https://hashnode.com/tag/backend-development)
-   [#apis](https://hashnode.com/tag/apis)
-   [#software-engineering](https://hashnode.com/tag/software-engineering)

## Written by

[Parsa Mohammadi](https://hashnode.com/@tomosu)

@tomosu · London, UK

  
[View profile](https://hashnode.com/@tomosu)

Production Reliability Governance for the AI Era

Tomosu continuously scores every application and closes its reliability gaps across development, pre-merge and runtime, using the Production Reliability Index (PRI) and a multi-tier agentic system.

## Responses 2

Markdown supported · ⌘↵ to post

[Mike Dabydeen](https://hashnode.com/@firelinks)

[Oct 26](https://hashnode.com/posts/why-requests-get-timeout-5-can-still-hang-and-how-to-set-a-total-deadline/6ade99556123af80316ccc42/comment/6adf36ffb03fc607cd39a1a4)

Subclassing requests.exceptions.Timeout keeps the old handlers working, and that includes retry wrappers. A tenacity or backoff decorator set to retry on Timeout will now retry a DeadlineExceeded as well, so get\_json with deadline\_s=4 and three attempts can hold the caller for 12 seconds plus backoff, past the 10 second endpoint budget in your example.

I'd compute the deadline once, before the retry loop, and give each attempt only the time left. The attempts then share one budget instead of each getting a fresh four seconds.

[Parsa Mohammadi](https://hashnode.com/@tomosu)

[Oct 26](https://hashnode.com/posts/why-requests-get-timeout-5-can-still-hang-and-how-to-set-a-total-deadline/6ade99556123af80316ccc42/comment/6adf36ffb03fc607cd39a1a4#reply-6adf400a336ac1971c45134f)

good catch, and it bites hardest when the upstream is already slow, since the retries pile onto the struggling dependency.
