import asyncio
async def hello():
print("Hello world!")
# 异步调用asyncio.sleep(1):
await asyncio.sleep(1)
print("Hello again!")
asyncio.run(hello())
import asyncio
import threading
async def hello(name):
# 打印name和当前线程:
print("Hello %s! (%s)" % (name, threading.current_thread))
# 异步调用asyncio.sleep(1):
await asyncio.sleep(1)
print("Hello %s again! (%s)" % (name, threading.current_thread))
return name
async def main():
list = await asyncio.gather(hello("Bob"), hello("Alice"))
print(list)
asyncio.run(main())