Asyncio in Python.

Asyncio

Asyncio is a library for writing single-threaded concurrent code using coroutines, multiplexing I/O access over sockets and other resources, and implementing network clients and servers.

import asyncio

async def my_coroutine():
    print("Starting coroutine")
    await asyncio.sleep(1)
    print("Coroutine finished")

async def main():
    print("Starting main")
    await my_coroutine()
    print("Main finished")

asyncio.run(main())

Output

Starting main
Starting coroutine
Coroutine finished
Main finished

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top