0%
简介
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
import time,random import asyncio,os
async def a(): for i in range(4): print(i,'a',os.getpid()) await asyncio.sleep(random.random()*2) return 'a function'
async def b(): for i in range(4): print(i,'b',os.getpid()) await asyncio.sleep(random.random() * 2) return 'b function'
async def main(): result = await asyncio.gather( a(), b() ) print(result[0],result[1])
if __name__=='__main__': start = time.time() asyncio.run(main()) print(time.time() - start) print('parant is %s' % os.getpid())
|