From fb9d2771d1c2114c664fa8a8bb02663b4dc9c9f1 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 21 Feb 2024 15:24:23 +0800 Subject: [PATCH] bugfid --- appPublic/worker.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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')