#asyncio Clear
Tags #php #kotlin #bash #go #sql #rust #typescript #html #java #python #files #utils #strings #http #concurrency #async #json #arrays #security #types #crypto #database #dates #format
Python Run sync Iterables as async Stream
Wrap a blocking iterator so each yield happens in a worker thread — useful when integrating sync libraries (DB cursors, file iterators) into an async pipeline without rewriting them.
Python Async Retry with Exponential Backoff
Retry an async operation up to N times, doubling the wait each attempt with random jitter to avoid thundering herd. Predicate controls retryability so 4xx errors stop immediately.
Python asyncio.gather with Errors Tolerated
`gather(*tasks)` cancels everything on the first failure — usually NOT what you want. `return_exceptions=True` lets every task finish, returning the exception in place of a result. Perfect for fan-out HTTP fetches.
Python asyncio Concurrency Limiter (Semaphore)
Run hundreds of coroutines but cap how many are in-flight at any moment. asyncio.Semaphore inside the task body is the cleanest way to "do at most 10 of these at a time."
Python asyncio.wait_for — Timeout Wrapper
Cancel a coroutine if it takes longer than `timeout` seconds. Raises asyncio.TimeoutError when fired so the caller can fall back. Python 3.11+ has asyncio.timeout() as a context-manager alternative.
Python asyncio.to_thread — Run Blocking Code
Wrap a blocking function so it doesn't freeze the event loop. asyncio.to_thread (3.9+) schedules the call onto the default executor and awaits the result.