Skip to main content

Practice · 1 of 1

Bounded async pipeline

CHALLENGE
Difficulty: advanced+25 XP

Implement async def pipeline(items, transform, workers=2, maxsize=3): - put all items through an asyncio.Queue(maxsize=maxsize) - workers async tasks consume and append await transform(item) results - the producer must NOT dump everything into the queue at once — with maxsize honored, queue backpressure applies (await q.put suspends when full) - return sorted(results) after await q.join(); cancel the workers afterwards

Back to lesson: Practice: Bounded Queue Practice