Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
Put explicit timeouts on every external call, run related calls in a TaskGroup so failures cancel siblings, let CancelledError propagate while cleaning up in finally, and limit concurrency with semaphores and bounded queues to apply backpressure.
Without timeouts, one slow dependency holds connections and memory until the service collapses, so wrap calls with asyncio.timeout or client-level timeouts, combined with retries with backoff only for safe operations. asyncio.TaskGroup, available since Python 3.11, cancels the remaining tasks when one fails and raises the errors as an ExceptionGroup, avoiding orphaned tasks that gather can leave behind. Cancellation is delivered as CancelledError at an await point; code should clean up in finally or async with blocks and re-raise it rather than swallow it. To avoid overload, cap concurrent downstream calls with asyncio.Semaphore and connection pool limits, use bounded queues between producers and consumers, and shed load or return errors early when limits are reached.