Bridging sync ↔ async & backpressure

P33.bridging.01 · Audience: guest, it-ml, language-pro · Prerequisites: Tasks, gather & timeouts

Real LLM grading for this pageLLM grading (this page):

The event loop is one thread, so a single blocking call freezes every coroutine. Real systems are full of blocking libraries and CPU-bound work, so you must bridge between the async and sync worlds without stalling the loop — and bound your queues so a fast producer can't exhaust memory. The kernel rung offloads a real blocking call to a thread.

Step 1 / 3Never block the loop
ⓘ Concept: One blocking call freezes everyone
The loop runs on a single thread. A blocking call — a slow synchronous library, time.sleep, heavy CPU — inside a coroutine holds that thread, so no other coroutine runs until it returns. Awaiting doesn't help if the work itself never yields.

Why it matters — This is the number-one asyncio production bug: a synchronous library call inside a coroutine silently stalls the entire service.

Ask the mentor about this module

Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.

Ctrl/Cmd + Enter to send

🎓 Practice ladder

2 graded rungs · ~20 min

Offload a real blocking call to a thread on the kernel, then explain bridging and backpressure — closing the P32 → P33 concurrency arc.

Rung 1 — don't block the loop: offload with to_thread (kernel)

Loading exercise…

Rung 2 — bridging & backpressure (interview)

Loading exercise…

That closes the concurrency arc: P32 gave you threads and processes, P33 gave you the event loop and how to bridge back to them. Next pillar: making it all fast.