vayu.aio¶
aio
¶
RateLimit
dataclass
¶
A cap of limit requests per period.
Attributes:
| Name | Type | Description |
|---|---|---|
limit |
int
|
Maximum number of requests allowed in each period. |
period |
timedelta
|
The rolling window, as a |
get_first_and_cancel_rest
async
¶
Await the first task to complete and cancel the rest.
Useful for "whoever answers first wins" patterns (e.g. racing a sleep against a shutdown event, or racing multiple identical HTTP calls).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*tasks
|
Union[Task, Coroutine]
|
Tasks or coroutines to race. |
()
|
Returns:
| Type | Description |
|---|---|
Task
|
The completed task. Call |
Source code in vayu/aio.py
sleep_until_signal
async
¶
Sleep for duration or until signal fires, whichever is first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
duration
|
Union[timedelta, Number]
|
A |
required |
signal
|
Event
|
An event that, when set, wakes the sleeper early. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in vayu/aio.py
attach_shutdown_signals
¶
Wire OS signals to an asyncio.Event so cooperating tasks can shut down cleanly.
Defaults to SIGINT and SIGTERM. Must be called from within a running
event loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shutdown
|
Event
|
The event to set when any of the signals is received. |
required |
signals
|
Optional[List]
|
Signals to attach. Defaults to |
None
|
Source code in vayu/aio.py
grab_all_urls
async
¶
grab_all_urls(
key_url_map: Dict[Any, str],
concurrency: int = 100,
timeout: int = 15,
print_progress: bool = True,
headers: Optional[Dict[str, str]] = None,
auth: Optional[BasicAuth] = None,
rate_limit: Optional[RateLimit] = None,
) -> Dict[Any, Any]
Fetch many URLs concurrently and return the responses keyed the same way.
Errors are captured, not raised: failed keys land in the result dict as
(None, "<exception repr>") so the caller can inspect or retry them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key_url_map
|
Dict[Any, str]
|
Mapping from caller-chosen key to URL. |
required |
concurrency
|
int
|
Upper bound on in-flight requests (also the |
100
|
timeout
|
int
|
Per-request timeout in seconds. |
15
|
print_progress
|
bool
|
If True, prints |
True
|
headers
|
Optional[Dict[str, str]]
|
Optional headers forwarded to every request. |
None
|
auth
|
Optional[BasicAuth]
|
Optional |
None
|
rate_limit
|
Optional[RateLimit]
|
Reserved for future use. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[Any, Any]
|
A dict keyed the same as |
Dict[Any, Any]
|
|
Dict[Any, Any]
|
on failure. |