MCPcopy Create free account
hub / github.com/KnowledgeXLab/LeanRAG / limit_async_func_call

Function limit_async_func_call

tools/_utils.py:232–251  ·  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

230
231# Decorators ------------------------------------------------------------------------
232def limit_async_func_call(max_size: int, waitting_time: float = 0.0001):
233 """Add restriction of maximum async calling times for a async func"""
234
235 def final_decro(func):
236 """Not using async.Semaphore to aovid use nest-asyncio"""
237 __current_size = 0
238
239 @wraps(func)
240 async def wait_func(*args, **kwargs):
241 nonlocal __current_size
242 while __current_size >= max_size:
243 await asyncio.sleep(waitting_time)
244 __current_size += 1
245 result = await func(*args, **kwargs)
246 __current_size -= 1
247 return result
248
249 return wait_func
250
251 return final_decro
252
253
254def wrap_embedding_func_with_attrs(**kwargs):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected