DEV Community

Claret Ibeawuchi
Claret Ibeawuchi

Posted on • Edited on

20 Keywords in Asynchronous Programming: Concurrency, Multiprocessing... all explained.

Welcome to the World of Asynchronous Programming in Python!

Welcome

As developers, we often encounter scenarios where waiting for certain tasks, such as input/output operations, can lead to inefficiencies in our programs.

Quick one: Think of such situations, if any, comment, let's have a discussion

Asynchronous programming is needed in multiple situations such as: I/O-Bound Operations, Web Development, Concurrency in Networking, GUI Applications, Real-Time Applications, Long-Running Tasks.

In this article, we'll explore the shift from traditional synchronous programming to the asynchronous paradigm in Python, uncovering powerful concepts and tools that enhance the efficiency and responsiveness of our applications.

Here are brief explanations of a list of important keywords related to asynchronous programming in Python:

Meme saying,

  1. Synchronous (Classic Sequential) Programming

    In synchronous programming, tasks run one after the other in a linear fashion. Each task must finish before the next one begins, leading to inefficiencies, especially in scenarios involving input/output operations.

  2. Asynchronous Programming

    Asynchronous code allows a program to signal that it will need to wait for certain tasks, such as input/output (I/O) operations, to complete. Instead of idly waiting, the program can continue executing other tasks. Common I/O-bound operations include network communication, file read/write, remote API calls, and database operations.

    Concurrency, not Multiprocessing or Multithreading:
    Asynchronous programming involves running one task at a time, not multithreading or multiprocessing. During the wait time of one function, another function can be executed.

  3. Global Interpreter Lock (GIL)

    The GIL in Python ensures that only one thread holds control of the interpreter at a time. While not impactful in single-threaded programs, it can be a bottleneck in CPU-bound and multi-threaded code.

  4. CPython

    CPython is the canonical implementation of the Python programming language, distributed on python.org. It's essential to distinguish CPython from other implementations like Jython or IronPython.

  5. Process

    A process is a separate instance of the Python interpreter, managed by the operating system and represented by a multiprocessing.Process object.

  6. Thread

    A thread is an entity within a process that can be scheduled for execution. Threads are smaller units of processing and are managed by the operating system.

  7. Thread Pool

    A thread pool is a collection of threads created in advance and reused to execute multiple tasks. Python's concurrent.futures.ThreadPoolExecutor simplifies thread pool management.

  8. Threading

    The concurrent.futures.ThreadPoolExecutor offers a higher-level interface for background thread execution. queue provides a thread-safe way to exchange data between threads, and asyncio offers task-level concurrency without the need for multiple OS threads.

  9. Multithreading

    Multithreading allows a processor to execute multiple threads concurrently, achieved through context switching.

  10. Multiprocessing

    Multiprocessing refers to a system's ability to support more than one processor simultaneously. Python's multiprocessing module leverages subprocesses, allowing full utilization of multiple processors.

  11. Parallelisation

    While modern computers can handle parallelism with multiple cores, Python's Global Interpreter Lock (GIL) limits true parallelism. The GIL restricts Python code to single-threaded execution.

  12. Concurrency

    Concurrency means running more than one task simultaneously, switching between tasks rather than running them in parallel.

  13. Coroutine

    Coroutines are a more generalized form of subroutines, executed using the async/await syntax. They allow the suspension and resumption of tasks, enhancing concurrency.

  14. AsyncIO

    AsyncIO is a library for writing concurrent code using async/await syntax. It serves as a foundation for various asynchronous frameworks in Python, suitable for IO-bound and high-level structured network code.

  15. Awaitable

    An awaitable is a Future-like object or a coroutine object, usable in an await expression.

  16. Event Loop

    An event loop runs in a thread and executes callbacks and tasks. Tasks are wrapped coroutines that can be executed independently.

  17. Task

    A task is a wrapped coroutine that can be executed independently.

  18. Futures

    Futures represent the result of an asynchronous computation.

  19. AnyIO

    AnyIO is an asynchronous networking and concurrency library compatible with both asyncio and trio. It implements structured concurrency on top of asyncio.

  20. Aiohttp

    Aiohttp is an asynchronous HTTP client/server for asyncio in Python.

Other helpful links:

With the knowledge you've been equipped with, you're ready to dive into the world of asynchronous programming. I have a follow up article here on Python Asyncio: A Guide to Asynchronous Programming and Concurrency.

Top comments (0)