diff --git a/appPublic/worker.py b/appPublic/worker.py index 773c2f5..5a92b04 100755 --- a/appPublic/worker.py +++ b/appPublic/worker.py @@ -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')