MCPcopy Create free account
hub / github.com/Enfoirer/Text2GraphRAG / limit_async_func_call

Function limit_async_func_call

nano_graphrag/_utils.py:276–295  ·  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

274
275# Decorators ------------------------------------------------------------------------
276def limit_async_func_call(max_size: int, waitting_time: float = 0.0001):
277 """Add restriction of maximum async calling times for a async func"""
278
279 def final_decro(func):
280 """Not using async.Semaphore to aovid use nest-asyncio"""
281 __current_size = 0
282
283 @wraps(func)
284 async def wait_func(*args, **kwargs):
285 nonlocal __current_size
286 while __current_size >= max_size:
287 await asyncio.sleep(waitting_time)
288 __current_size += 1
289 result = await func(*args, **kwargs)
290 __current_size -= 1
291 return result
292
293 return wait_func
294
295 return final_decro
296
297
298def wrap_embedding_func_with_attrs(**kwargs):

Callers 1

__post_init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected