Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The requests module internally works with Session objects. These can be customised in behaviour e.g. using retry adapters. This is extremely useful for error handling because the user application doesn't even get to see and need to handle errors until a configurable number of retries with optional backoff has been tried. Unfortunately, the module-level API of the requests module does not allow to supply such a customised Session object. Instead it creates a new Session for each request and needs to use it as a context handler to make sure it leaks no sockets - see https://github.com/psf/requests/blob/143150233162d609330941ec2aacde5ed4caa510/requests/api.py#L57 for details. The module-level API is a very thin shim which direcly hands all requests to this per-request Session object. This change switches the Cortex API layer to use a Session object for requests directly and adds a parameter so users can provide their own customised Session object. As a side-effect, this switches the module to using a persistent Session object that is re-used across requests. This should be more efficient in that it can re-use an established connection and potentially connection pooling.
- Loading branch information