🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Python Advanced

What is Python Coroutine?

A function defined with async def that can be paused and resumed, enabling concurrent execution without threads.

Coroutines are the foundation of Python's asyncio framework. Defined with async def, they use await to suspend execution while waiting for I/O operations (network requests, file reads, database queries). The event loop manages multiple coroutines, switching between them when one awaits. This achieves concurrency without thread overhead or the complexity of multiprocessing. Coroutines are not parallel — they run on a single thread but overlap waiting time efficiently. Key patterns include async for (async iteration), async with (async context managers), and asyncio.gather() for running multiple coroutines concurrently.

Related Terms

Python Descriptors
Objects that define __get__, __set__, or __delete__ methods, controlling how attribute access works on other objects.
Magic Methods
Special double-underscore methods that define how Python objects behave with built-in operations and functions.
Generator
A function that yields values one at a time using the yield keyword, enabling memory-efficient iteration over large datasets.
Flask
A lightweight web framework for Python that provides essentials for building web applications without imposing structure.
GIL (Global Interpreter Lock)
A mutex in CPython that allows only one thread to execute Python bytecode at a time, limiting true parallelism.
Python Package
A directory containing Python modules and an __init__.py file, providing a way to organize and distribute reusable code.
View All Python Terms →