Urgent.News

What's breaking now, across thousands of outlets.

Tech

Python: Call Multiple APIs in Parallel with asyncio.gather and Semaphore in 10 Minutes

When you need to call dozens of APIs — syncing data, crawling prices, firing webhooks — a sequential for loop adds up the waiting time of every request: 20 requests × 1 second = 20 seconds. asyncio.gather runs many coroutines concurrently inside a single event loop, while asyncio.Semaphore limits how many requests fly at the same time so you don't overwhelm the partner API. This technique applies…

When you need to call multiple APIs simultaneously, sequencing them with loops adds up all the waiting time. Using asyncio.gather and Semaphore, you can run coroutines concurrently inside a single event loop, speeding up I/O-bound tasks like HTTP calls. To avoid overwhelming partner APIs, Semaphore limits the number of concurrent requests.

For each of 20 users, fetching info from a partner API that takes about 1 second each sequentially would take ≈ 20 seconds. By using asyncio.gather with Semaphore(5), you can run up to 5 requests concurrently, reducing the total time to ≈ 4 seconds. To handle errors, use return_exceptions=True, allowing the function to return a list of results including any exceptions that occurred.

Start with Semaphore(5) and adjust based on the API's response limits and observed performance. Remember, this technique is useful for any I/O-bound tasks but not for CPU-bound work.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Drafting Rights: Assign Every Doc Section to a Model or a Named Human

Most documentation pipelines fail on accountability rather than prose quality, because nobody can point at a sentence and name the human who approved it.

  • Models can draft only current behavior sections
  • Future functionality promises prohibited for models
  • Manifest file docs-rights.yml enforces tiers

Meet LiveReview: Auto Approve 30-50% of Your Low-Risk PRs, Safely

Earlier this year, we built a small tool called git-lrc . It fixed one problem: engineers committing AI-written code they had not read.

  • LiveReview auto-approves 30-50% low-risk PRs
  • System uses semantic LLM, custom ML, static analysis
  • Provides checkpoints for custom risk enforcement

Your Timer Is a Wall Clock, Not a Stopwatch: Four Elapsed-Time Myths and a Monotonic Probe

How long did that batch job take? Simple question. Your logs probably answer it wrong. I kept seeing two numbers for one run. The job log said eleven minutes. The dashboard said forty-two.

  • Wall clock measures what time it is, not how long a task took
  • Monotonic clock never goes backward, suitable for measuring durations
  • Timeouts indicate local socket issue, not remote task completion

More from Saturday 7 November →