asyncio 模块
import asyncio
async def hello():
print('Hello start!')
await asyncio.sleep(2)
print('Hello end!')
async def hello222():
print('Hello222 start!')
result = await somework()
print('Hello222 end', result)
async def somework():
print('somework start...')
await asyncio.sleep(3)
print("somework end ")
return ("sleep 3 s")
loop = asyncio.get_event_loop()
tasks = [hello(), hello222()]
loop.run_until_complete(asyncio.wait(tasks))
loop.close()

浙公网安备 33010602011771号