bugfid
This commit is contained in:
parent
b97c946891
commit
fb9d2771d1
@ -1,3 +1,4 @@
|
||||
import time
|
||||
import random
|
||||
import asyncio
|
||||
import inspect
|
||||
@ -43,12 +44,19 @@ class AsyncWorker:
|
||||
if __name__ == '__main__':
|
||||
def hello(cnt,greeting):
|
||||
t = random.randint(1,10)
|
||||
# await asyncio.sleep(t)
|
||||
print(cnt,'will sleep ',t,'seconds')
|
||||
time.sleep(t)
|
||||
print(cnt,'cost ',t,'seconds to',greeting)
|
||||
|
||||
async def ahello(cnt,greeting):
|
||||
t = random.randint(1,10)
|
||||
print(cnt,'will sleep ',t,'seconds')
|
||||
await asyncio.sleep(t)
|
||||
print(cnt,'cost ',t,'seconds to',greeting)
|
||||
|
||||
async def run():
|
||||
w = AsyncWorker()
|
||||
g = [ asyncio.create_task(w(hello,i,'hello world')) for i in range(1000) ]
|
||||
g = [ asyncio.create_task(w(hello,i,'hello world')) for i in range(100) ]
|
||||
await asyncio.wait(g)
|
||||
print('aaaaaaaaaaaaaaaaaaa')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user