MCPcopy Create free account
hub / github.com/NanGePlus/LightRAGTest / limit_async_func_call

Function limit_async_func_call

LightRAG/lightrag/utils.py:93–112  ·  view source on GitHub ↗

Add restriction of maximum async calling times for a async func

(max_size: int, waitting_time: float = 0.0001)

Source from the content-addressed store, hash-verified

91
92
93def limit_async_func_call(max_size: int, waitting_time: float = 0.0001):
94 """Add restriction of maximum async calling times for a async func"""
95
96 def final_decro(func):
97 """Not using async.Semaphore to aovid use nest-asyncio"""
98 __current_size = 0
99
100 @wraps(func)
101 async def wait_func(*args, **kwargs):
102 nonlocal __current_size
103 while __current_size >= max_size:
104 await asyncio.sleep(waitting_time)
105 __current_size += 1
106 result = await func(*args, **kwargs)
107 __current_size -= 1
108 return result
109
110 return wait_func
111
112 return final_decro
113
114
115def wrap_embedding_func_with_attrs(**kwargs):

Callers 1

__post_init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected