bugfix
This commit is contained in:
parent
96417aa3e0
commit
b9f6e47c55
@ -1,4 +1,4 @@
|
|||||||
|
import random
|
||||||
import asyncio
|
import asyncio
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
@ -10,8 +10,8 @@ def asyncCall(func):
|
|||||||
return wraped_func
|
return wraped_func
|
||||||
|
|
||||||
class Worker:
|
class Worker:
|
||||||
def __init__(self,max=50):
|
def __init__(self,maxtask=50):
|
||||||
self.semaphore = asyncio.Semaphore(max)
|
self.semaphore = asyncio.Semaphore(maxtask)
|
||||||
|
|
||||||
async def __call__(self,callee,*args,**kw):
|
async def __call__(self,callee,*args,**kw):
|
||||||
async with self.semaphore:
|
async with self.semaphore:
|
||||||
@ -28,8 +28,9 @@ class Worker:
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
async def hello(cnt,greeting):
|
async def hello(cnt,greeting):
|
||||||
await asyncio.sleep(1)
|
t = random.randint(1,10)
|
||||||
print(cnt,greeting)
|
await asyncio.sleep(t)
|
||||||
|
print(cnt,'cost ',t,'seconds to',greeting)
|
||||||
|
|
||||||
|
|
||||||
async def run():
|
async def run():
|
||||||
|
Loading…
Reference in New Issue
Block a user