Answers for "asyncio run function"

6

python async await

import asyncio

async def print_B(): #Simple async def
    print("B")

async def main_def():
    print("A")
    await asyncio.gather(print_B())
    print("C")
asyncio.run(main_def())

# The function you wait for must include async
# The function you use await must include async
# The function you use await must run by asyncio.run(THE_FUNC())
Posted by: Guest on February-04-2021
1

asyncio sleep

#will sleep the current corutien for set numner of seconds
import asyncio
await asyncio.sleep(1)
Posted by: Guest on January-19-2021
0

asyncio run

>>> import asyncio

>>> async def main():
...     print('hello')
...     await asyncio.sleep(1)
...     print('world')

>>> asyncio.run(main())
hello
world
Posted by: Guest on February-23-2021

Python Answers by Framework

Browse Popular Code Answers by Language