Python2 HTTPAdapter: How to Handle Persistent Connections and Timeouts Effectively?

18 Replies, 1670 Views

Python2 HTTPAdapter is a beast, no doubt. For persistent connections, I’ve had some success with manually closing connections after a certain number of requests. It’s not ideal, but it prevents hangs.

For timeouts, try using `requests` with a custom session and setting `timeout=(connect_timeout, read_timeout)`. It’s not perfect, but it’s better than relying on the default behavior.

Also, if you’re dealing with a lot of requests, consider using `grequests`—it’s async and handles timeouts better.

Messages In This Thread



Users browsing this thread: 1 Guest(s)