What is the threading library in Python and how to use it?
Python's threading module runs code in multiple threads, ideal for I/O-bound work. Learn Thread, ThreadPoolExecutor, locks, queues, events, and the GIL.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Python's threading module runs code in multiple threads, ideal for I/O-bound work. Learn Thread, ThreadPoolExecutor, locks, queues, events, and the GIL.
The subprocess module starts external programs from Python and captures their output and exit codes. Learn run(), Popen, pipes, timeouts, and safe argument handling.
Python's multiprocessing module runs code in separate processes so CPU-bound work can use every core. See Process, Queue, Pool and shared memory with working examples.
concurrent.futures runs callables on thread or process pools and returns Future objects. Learn submit, map, as_completed, errors and when to pick each pool.
asyncio is the Python standard library for concurrency with async and await. Learn how the event loop, tasks and TaskGroup work, with runnable examples.
async def defines a Python coroutine that an event loop runs. Learn how await, TaskGroup and gather enable concurrent I/O-bound code.
An async generator yields values while awaiting I/O and is consumed with async for. Learn syntax, streaming, cleanup and common mistakes.
async with runs asynchronous setup and cleanup around a block of code. Learn how __aenter__ and __aexit__ work, and how to write your own with asynccontextmanager.
async for iterates over asynchronous iterables in Python without blocking the event loop. See how it works, with async generators, custom iterators and real examples.
await suspends an async function until an awaitable completes, letting other tasks run. See what can be awaited, how to run awaits concurrently and what to avoid.
The async keyword defines Python coroutines that can pause at await. See how async def works with asyncio, how to run tasks concurrently and what to avoid.
Learn how the Python with statement uses context managers to set up and clean up resources, with file, transaction and contextlib examples.
A metaclass is the class of a class, and type is the default. Learn how to create custom metaclasses, real use cases and simpler alternatives.
Descriptors are objects with __get__, __set__ or __delete__ that customise attribute access. See how property, methods and validators are built on them.
A Python property lets attribute access run code. Learn @property, setters, read-only attributes, validation and cached_property.
A Python static method takes no self or cls and works like a function inside a class. See syntax, class method differences and when to use it.
A class method receives the class as cls and is declared with @classmethod. See how it differs from instance and static methods and how to use it for factories.
The __le__ method customizes the <= operator for your classes. See return values, NotImplemented, total_ordering and dataclass(order=True).
The __ge__ method defines the >= operator for your classes. See how NotImplemented, reflected methods, total_ordering and dataclasses fit together.
__lt__ defines the < operator for your classes and is all sorted(), min(), max() and heapq need. Learn the correct pattern and common pitfalls.