Junior — Middle
Do you have practical experience using the AsyncIO library for asynchronous programming?
sobes.tech AI
Answer from AI
Yes, the AsyncIO library in Python is used for writing asynchronous code that allows performing I/O operations without blocking the main thread.
Main elements of AsyncIO:
- Event loop, which manages task execution.
- Coroutines — functions that can be paused and resumed.
- Futures and Tasks for managing asynchronous operations.
Example of simple async code:
import asyncio
async def say_hello():
print('Hello')
await asyncio.sleep(1)
print('World')
asyncio.run(say_hello())
This code prints "Hello", waits 1 second without blocking the thread, then prints "World".