Jason Brownlee's Blog, page 31
November 16, 2022
Performance May Not Scale with CPU Cores in Python
We expect the performance of executing independent tasks in parallel to scale with the number of physical CPU cores available. This assumption is true, but only with some types of tasks. There are some tasks where this expectation does not hold, such as working with large lists. In this tutorial, you will discover some independent […]
Published on November 16, 2022 13:10
How to Get All Asyncio Tasks in Python
You can get all tasks in an asyncio program via the asyncio.all_tasks() function. In this tutorial, you will discover how to get all asyncio tasks in Python. Let’s get started. What is an Asyncio Task An asyncio Task is an object that schedules and independently runs an asyncio coroutine. It provides a handle on a […]
Published on November 16, 2022 10:00
November 15, 2022
Parallel Nested For-Loops in Python
You can convert nested for-loops to execute concurrently or in parallel in Python using thread pools or process pools, depending on the types of tasks that are being executed. In this tutorial, you will discover how to change a nested for-loop to be concurrent or parallel in Python with a suite of worked examples. This […]
Published on November 15, 2022 14:00
How to Get the Current Asyncio Task in Python
You can get the current task via asyncio.current_task() function. In this tutorial, you will discover how to get and use the current asyncio task in Python. Let’s get started. What is an Asyncio Task An asyncio Task is an object that schedules and independently runs an asyncio coroutine. It provides a handle on a scheduled […]
Published on November 15, 2022 10:00
November 14, 2022
How to Get the Asyncio Coroutine from a Task in Python
You can get the coroutine wrapped in a task by calling the get_coro() method on the Task object. In this tutorial, you will discover how to get the coroutine from an asyncio task in Python. Let’s get started. What is an Asyncio Task An asyncio Task is an object that schedules and independently runs an […]
Published on November 14, 2022 10:00
November 13, 2022
How to Use Asyncio Task Done Callback Functions
You can add a done callback function to a task via the add_done_callback() method and specify the function name. Done callback functions can be removed from a task via the remove_done_callback() method. In this tutorial, you will discover how to use asyncio task done callback functions in Python. Let’s get started. What is an Asyncio […]
Published on November 13, 2022 10:00
November 12, 2022
How to Get and Set Asyncio Task Names
You can set an asyncio task name via the “name” argument to the asyncio.Task class constructor or via the set_name() method on a Task object. The name of a task can be accessed via the get_name() method on a Task object. In this tutorial, you will discover how to set and get the name of […]
Published on November 12, 2022 10:00
November 11, 2022
How to Handle Asyncio Task Exceptions
You can retrieve an exception in a coroutine wrapped in a Task via the exception() method. In this tutorial, you will discover how to handle exceptions in asyncio tasks in Python. Let’s get started. What is an Asyncio Task An asyncio Task is an object that schedules and independently runs an asyncio coroutine. It provides […]
Published on November 11, 2022 13:00
How to Cancel an Asyncio Task
You can cancel a task in asyncio via the cancel() method on a Task object. In this tutorial, you will discover how to cancel asyncio tasks in Python. Let’s get started. What is an Asyncio Task An asyncio Task is an object that schedules and independently runs an asyncio coroutine. It provides a handle on […]
Published on November 11, 2022 10:00
November 10, 2022
How to Get Asyncio Task Results
You can get the return value result from an asyncio task by calling the result() method on the Task object. In this tutorial, you will discover how to get a result from an asyncio task in Python. Let’s get started. What is an Asyncio Task An asyncio Task is an object that schedules and independently […]
Published on November 10, 2022 10:00


