Skip to content

Commit c3e5855

Browse files
committed
fix docs, add support for sync timeout override
1 parent d815106 commit c3e5855

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

ipinfo/handler_async.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ async def deinit(self):
8686
await self.httpsess.close()
8787
self.httpsess = None
8888

89-
async def getDetails(self, ip_address=None):
89+
async def getDetails(self, ip_address=None, timeout=None):
9090
"""Get details for specified IP address as a Details object."""
9191
self._ensure_aiohttp_ready()
9292

@@ -106,7 +106,10 @@ async def getDetails(self, ip_address=None):
106106
if ip_address:
107107
url += "/" + ip_address
108108
headers = handler_utils.get_headers(self.access_token)
109-
async with self.httpsess.get(url, headers=headers) as resp:
109+
req_opts = {}
110+
if timeout is not None:
111+
req_opts["timeout"] = timeout
112+
async with self.httpsess.get(url, headers=headers, **req_opts) as resp:
110113
if resp.status == 429:
111114
raise RequestQuotaExceededError()
112115
resp.raise_for_status()
@@ -135,8 +138,25 @@ async def getBatchDetails(
135138
input list).
136139
137140
The input list is broken up into batches to abide by API requirements.
138-
The batch size can be adjusted with `batch_size` but is clipped to (and
139-
also defaults to) `BATCH_MAX_SIZE`.
141+
The batch size can be adjusted with `batch_size` but is clipped to
142+
`BATCH_MAX_SIZE`.
143+
Defaults to `BATCH_MAX_SIZE`.
144+
145+
For each batch, `timeout_per_batch` indicates the maximum seconds to
146+
spend waiting for the HTTP request to complete. If any batch fails with
147+
this timeout, the whole operation fails.
148+
Defaults to `BATCH_REQ_TIMEOUT_DEFAULT` seconds.
149+
150+
`timeout_total` is a seconds-denominated hard-timeout for the time
151+
spent in HTTP operations; regardless of whether all batches have
152+
succeeded so far, if `timeout_total` is reached, the whole operation
153+
will fail by raising `TimeoutExceededError`.
154+
Defaults to being turned off.
155+
156+
`raise_on_fail`, if turned off, will return any result retrieved so far
157+
rather than raise an exception when errors occur, including timeout and
158+
quota errors.
159+
Defaults to on.
140160
141161
The concurrency level is currently unadjustable; coroutines will be
142162
created and consumed for all batches at once.

0 commit comments

Comments
 (0)