Connection pooling
Requests use urllib3 under the hood, which will create one pool of connectors per host you are calling and reuse them when the code calls a host.
In other words, if your service calls several other services, you don't need to worry about recycling connections made to those services; requests should handle it for you.
Flask is a synchronous framework, so if you are running with a single thread, which is the default behavior, then the requests library's connection pooling doesn't help you much. Every call will happen one after the other. Requests should only keep one connector open per remote host.
But if you run your Flask application with several threads and have a lot of concurrent connections, these pools can play a vital ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access