Jason Brownlee's Blog, page 25

January 31, 2023

Coroutines Use Less Memory Than Threads in Python

It is commonly stated that coroutines use less memory than threads. We can explore this statement using experiments and report actual numbers. Results suggest, at least on one modern system, that threads use twice as much memory as coroutines. In this tutorial, you will discover and confirm that coroutines use less memory than threads. Let’s […]
 •  0 comments  •  flag
Share on Twitter
Published on January 31, 2023 10:00

January 29, 2023

Coroutines Are Faster To Start Than Threads in Python

You can compare the time taken to create many threads to the time taken to create many coroutines. This provides a practical way to compare coroutines to threads in the context of the often-quoted statement that coroutines are faster to create than threads. In this tutorial, you will discover how to benchmark the time taken […]
 •  0 comments  •  flag
Share on Twitter
Published on January 29, 2023 10:00

January 26, 2023

RuntimeWarning: Coroutine Was Never Awaited

You can resolve the RuntimeWarning “Coroutine Was Never Awaited” by running the coroutine object. It is common to see this warning message when calling a coroutine function but failing to execute the coroutine object that is returned either via asyncio.run() or by awaiting it. In this tutorial, you will discover how to fix the RuntimeWarning […]
 •  0 comments  •  flag
Share on Twitter
Published on January 26, 2023 10:00

January 24, 2023

What is Async/Await in Python

You can use the async/await pattern in Python to implement asynchronous programming. In this tutorial, you will discover async/await in Python and exactly what it means and when to use it. Let’s get started. What is Async/Await Async/await refers to a pattern used for asynchronous programming. In computer programming, the async/await pattern is a syntactic […]
 •  0 comments  •  flag
Share on Twitter
Published on January 24, 2023 10:00

What is Asyncio/Await in Python

You can use the async/await pattern in Python to implement asynchronous programming. In this tutorial, you will discover async/await in Python and exactly what it means and when to use it. Let’s get started. What is Async/Await Async/await refers to a pattern used for asynchronous programming. In computer programming, the async/await pattern is a syntactic […]
 •  0 comments  •  flag
Share on Twitter
Published on January 24, 2023 10:00

January 22, 2023

5 Common Asyncio Errors in Python (and how to avoid them)

Asyncio provides asynchronous programming in Python with coroutines. It is exciting, new, and can be deeply frustrating to beginners. The reason is because of a series of common errors made when getting started with coroutines and the asyncio API. In this tutorial, you will discover the most common errors encountered by beginners in asyncio in […]
 •  0 comments  •  flag
Share on Twitter
Published on January 22, 2023 10:00

January 19, 2023

Asyncio vs Threading in Python

Asyncio provides coroutine-based concurrency for non-blocking I/O with streams and subprocesses. Threading provides thread-based concurrency, suitable for blocking I/O tasks. In this tutorial, you will discover the difference between Asyncio and Threading and when to use each in your Python projects. Let’s get started. What is Asyncio The “asyncio” module provides coroutine-based concurrency in Python. […]
 •  0 comments  •  flag
Share on Twitter
Published on January 19, 2023 10:00

January 17, 2023

How to Wait for All Background Asyncio Tasks in Python

You can wait for many independent tasks to complete by first getting the set of all running tasks, removing the current task, then waiting on the remaining tasks in the set. This will allow an asyncio program to schedule many independent tasks throughout its lifetime and for the main coroutine to wait for them to […]
 •  0 comments  •  flag
Share on Twitter
Published on January 17, 2023 10:00

January 15, 2023

Asyncio Coroutine Function and Coroutine Types

You can programmatically identify coroutine functions and coroutines using the inspect module API. Coroutines have a specific “coroutine” type that shares methods with generators as well as the awaitable interface. In this tutorial, you will discover coroutine functions and coroutine types in Python. Let’s get started. Asyncio Coroutine Types Modern Python includes changes to the […]
 •  0 comments  •  flag
Share on Twitter
Published on January 15, 2023 10:00

January 12, 2023

How to Run a Follow-Up Task in Asyncio

You can schedule follow-up tasks in asyncio either directly from the primary task, from the caller of the primary task, or automatically from a done callback function. In this tutorial, you will discover how to schedule and run follow-up asyncio tasks in Python. Let’s get started. Need to Run a Follow-Up Task in Asyncio We […]
 •  0 comments  •  flag
Share on Twitter
Published on January 12, 2023 10:00