Skip to main content

How do Python coroutines work?

Mid Python
Quick Answer Coroutines are functions defined with async def that can suspend at await points. When a coroutine awaits something (asyncio.sleep, aiohttp request), control returns to the event loop which runs other coroutines. Unlike threads, coroutines switch cooperatively (at await) not preemptively. This enables thousands of concurrent operations with minimal memory compared to threads.

Answer

Coroutines defined with async def.
Execution suspends at await points.
Useful for pipelines, cooperative multitasking, and event-driven systems.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice