Skip to content

non-blocking operation

In Python, a non-blocking operation is an operation that allows your program to continue executing other tasks without waiting for the operation to complete. This is particularly useful when dealing with I/O-bound tasks such as reading from or writing to a file, making network requests, or interacting with databases.

By using non-blocking operations, you can enhance the efficiency and responsiveness of your programs, as they can perform other computations or handle multiple tasks concurrently while waiting for an input/output (I/O) operation to finish. These types of operations are a key feature in asynchronous programming.

Example

Here’s an example using Python’s asyncio module to demonstrate non-blocking operations with the async and await keywords:

Python
>>> import asyncio

>>> async def fetch_data():
...     print("Start fetching data...")
...     await asyncio.sleep(2)
...     print("Data fetched!")
...

>>> async def main():
...     task1 = asyncio.create_task(fetch_data())
...     task2 = asyncio.create_task(fetch_data())
...     await task1
...     await task2
...

>>> asyncio.run(main())
Start fetching data...
Start fetching data...
Data fetched!
Data fetched!

In this example, the fetch_data() function simulates a non-blocking I/O operation using asyncio.sleep(), which doesn’t block the event loop. Both tasks are scheduled and start running concurrently when create_task() is called. The await statements then wait for each task to complete.

Tutorial

Python's asyncio: A Hands-On Walkthrough

Explore how Python asyncio works and when to use it. Follow hands-on examples to build efficient programs with coroutines and awaitable tasks.

advanced python

For additional information on related topics, take a look at the following resources:


By Leodanis Pozo Ramos • Updated March 10, 2026 • Reviewed by Dan Bader