Jason Brownlee's Blog, page 6

January 18, 2024

How to Lint (Static Analysis) Asyncio Code

You can identify common problems in asyncio programs using popular Python static analysis tools such as pylint and flake8. In this tutorial, you will discover how to lint python code for common asyncio problems. Let’s get started. What is Lint or Linting? Linting refers to tools for performing a static analysis check of code. Lint […]
 •  0 comments  •  flag
Share on Twitter
Published on January 18, 2024 10:00

January 16, 2024

RuntimeWarning: Enable tracemalloc to get the object allocation traceback

You may get a warning when running your asyncio program that looks like: “RuntimeWarning: Enable tracemalloc to get the object allocation traceback“. This warning is caused by not awaiting a coroutine in an asyncio program and giving a suggestion on how to track down the cause. It can be fixed by awaiting the offending coroutine […]
 •  0 comments  •  flag
Share on Twitter
Published on January 16, 2024 10:00

January 14, 2024

Asyncio Log Exceptions

You can log exceptions in asyncio programs by calling logging.exception() within tasks or when awaiting tasks. We can also configure the event loop to automatically log never-retrieved exceptions when the program is shut down. In this tutorial, you will discover how to log exceptions from asyncio. Let’s get started. Need to Log Exceptions in Asyncio […]
 •  0 comments  •  flag
Share on Twitter
Published on January 14, 2024 10:00

January 11, 2024

Configure, Suppress, and Log Asyncio Warnings

You can configure, suppress, and log warnings emitted by asyncio programs. By default, the asyncio event loop will emit warnings in situations that are not harmful to the running program but should be inspected and changed by the developer. More warnings can be enabled in the programs, and we can choose to filter out and […]
 •  0 comments  •  flag
Share on Twitter
Published on January 11, 2024 10:00

January 9, 2024

Asyncio Log To File

You can log to a file from an asyncio program by initializing the Python logging infrastructure and configuring it to use a FileHandler. In this tutorial, you will discover how to log to a file from an asyncio program. Let’s get started. Need to Log To File in Asyncio Program Logging is a way of […]
 •  0 comments  •  flag
Share on Twitter
Published on January 09, 2024 10:00

January 7, 2024

Daemon Asyncio Task in Python

You can develop a daemon asyncio task that runs in the background by running a coroutine in the background. Background asyncio tasks will be canceled automatically when the event loop is terminated, meaning that we don’t need to explicitly terminate them at the end of our programs. In this tutorial, you will discover how to […]
 •  0 comments  •  flag
Share on Twitter
Published on January 07, 2024 10:00

January 4, 2024

Asyncio Logging Without Blocking

You can implement non-blocking logging in asyncio programs by using a shared Queue with a QueueHandler to log messages and a QueueListener to store log messages. In this tutorial, you will discover how to log without blocking from asyncio programs in Python. Let’s get started. What is Logging Logging is a way of tracking events […]
 •  0 comments  •  flag
Share on Twitter
Published on January 04, 2024 10:00

January 2, 2024

Asyncio Task CancelledError Propagation

You can cancel asyncio tasks and the request to cancel can propagate down a hierarchy of awaiting tasks. The resulting CancelledError exceptions can then bubble back up the hierarchy. In this tutorial, you will discover how CancelledError exceptions propagate when an asyncio task is cancelled. Let’s get started. What is Asyncio Task Cancellation? Asyncio tasks […]
 •  0 comments  •  flag
Share on Twitter
Published on January 02, 2024 10:00

January 1, 2024

Python Asyncio Database Drivers

Asyncio has found a home in Python web development and many asyncio web development projects require database access. This means there is a need for Python database drivers that support asyncio. This support may be naive via an async-first driver, or provided via a wrapper around a blocking I/O database driver that simulates async/await syntax […]
 •  0 comments  •  flag
Share on Twitter
Published on January 01, 2024 10:00

December 31, 2023

When Does Asyncio Switch Between Tasks

You may be wondering how asyncio chooses which task to run and how it switches between tasks. This is an important question and highlights how asyncio tasks are different from typical Python functions and thread-based concurrency. In this tutorial, you will discover how asyncio switches between tasks and coroutines and how this is different from […]
 •  0 comments  •  flag
Share on Twitter
Published on December 31, 2023 10:00