Commit 96fa5dc
committed
Allow for custom requests sessions
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.1 parent e9f70f4 commit 96fa5dc
1 file changed
+6
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
64 | | - | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | | - | |
| 82 | + | |
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
| |||
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | | - | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| |||
115 | 116 | | |
116 | 117 | | |
117 | 118 | | |
118 | | - | |
| 119 | + | |
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | | - | |
| 136 | + | |
136 | 137 | | |
137 | 138 | | |
138 | 139 | | |
| |||
0 commit comments