Learn Before
Code

Asyncio Example

In this example:

import asyncio async def f(): print("Hello") await asyncio.sleep(1) print("World") if __name__ == "__main__": asyncio.run(main())

The coroutine is executed and subsequently prints "Hello". Next, the coroutine suspends and waits for asyncio.sleep(1) to finish before continuing. During this time , the main program is allowed to execute other code. Once asyncio.sleep(1) finishes, the coroutine completes by printing "World"

0

1

Updated 2021-04-30

Tags

Python Programming Language

Data Science

Learn After