turboapi 0.3.28__cp313-cp313-win_amd64.whl → 0.3.29__cp313-cp313-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -0,0 +1,86 @@
1
+ """
2
+ Async Limiter - Semaphore-based rate limiting for async tasks
3
+
4
+ Prevents event loop overload by limiting concurrent async tasks.
5
+ """
6
+
7
+ import asyncio
8
+ from typing import Any, Coroutine
9
+
10
+
11
+ class AsyncLimiter:
12
+ """Semaphore-based limiter for async tasks
13
+
14
+ Limits the number of concurrent async tasks to prevent event loop overload.
15
+ This is critical for maintaining stable performance under high load.
16
+
17
+ Args:
18
+ max_concurrent: Maximum number of concurrent tasks (default: 512)
19
+
20
+ Example:
21
+ limiter = AsyncLimiter(max_concurrent=512)
22
+ result = await limiter(some_coroutine())
23
+ """
24
+
25
+ def __init__(self, max_concurrent: int = 512):
26
+ self.semaphore = asyncio.Semaphore(max_concurrent)
27
+ self.max_concurrent = max_concurrent
28
+ self._active_tasks = 0
29
+
30
+ async def __call__(self, coro: Coroutine) -> Any:
31
+ """Execute coroutine with semaphore gating
32
+
33
+ Args:
34
+ coro: Coroutine to execute
35
+
36
+ Returns:
37
+ Result of the coroutine
38
+ """
39
+ async with self.semaphore:
40
+ self._active_tasks += 1
41
+ try:
42
+ return await coro
43
+ finally:
44
+ self._active_tasks -= 1
45
+
46
+ @property
47
+ def active_tasks(self) -> int:
48
+ """Get current number of active tasks"""
49
+ return self._active_tasks
50
+
51
+ @property
52
+ def available_slots(self) -> int:
53
+ """Get number of available slots"""
54
+ return self.max_concurrent - self._active_tasks
55
+
56
+
57
+ # Global limiter instance per event loop
58
+ _limiters = {}
59
+
60
+
61
+ def get_limiter(max_concurrent: int = 512) -> AsyncLimiter:
62
+ """Get or create limiter for current event loop
63
+
64
+ Args:
65
+ max_concurrent: Maximum concurrent tasks
66
+
67
+ Returns:
68
+ AsyncLimiter instance for current event loop
69
+ """
70
+ try:
71
+ loop = asyncio.get_running_loop()
72
+ loop_id = id(loop)
73
+
74
+ if loop_id not in _limiters:
75
+ _limiters[loop_id] = AsyncLimiter(max_concurrent)
76
+
77
+ return _limiters[loop_id]
78
+ except RuntimeError:
79
+ # No running loop, create standalone limiter
80
+ return AsyncLimiter(max_concurrent)
81
+
82
+
83
+ def reset_limiters():
84
+ """Reset all limiters (useful for testing)"""
85
+ global _limiters
86
+ _limiters = {}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: turboapi
3
- Version: 0.3.28
3
+ Version: 0.3.29
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: License :: OSI Approved :: MIT License
@@ -1,7 +1,8 @@
1
- turboapi-0.3.28.dist-info/METADATA,sha256=T1NpF_kL7xM6dTysG2jKQPVyJ85m0q2ffvCDpwCMnKs,1458
2
- turboapi-0.3.28.dist-info/WHEEL,sha256=TJQY77QRLvXq32tEs9ATmwKO6NAOtuKOAw50eyiSmWU,96
1
+ turboapi-0.3.29.dist-info/METADATA,sha256=f7OQHFLD1b8RUY8576jIQ3cC4oSh8HjxZFnWwqk5lMY,1458
2
+ turboapi-0.3.29.dist-info/WHEEL,sha256=TJQY77QRLvXq32tEs9ATmwKO6NAOtuKOAw50eyiSmWU,96
3
3
  turboapi/__init__.py,sha256=r9Fphtu9ruHFUhSpBMAGxY5en2wvcnsE1nMp2DDRM6w,692
4
- turboapi/_rust.cp313-win_amd64.pyd,sha256=qJsomUpv-aKgCBiSCpg1Z7xxB3O6lnhDV813m32pK_0,3554304
4
+ turboapi/_rust.cp313-win_amd64.pyd,sha256=Gm3goMutZD5MHssCvWwFPShk1JSZc2UgBj9nHfbgWbY,3551232
5
+ turboapi/async_limiter.py,sha256=x2qkloPbg2YelDNUXKya2BwBTq5zVxDHxuaQspIgYBg,2416
5
6
  turboapi/async_pool.py,sha256=UVm0A-0jIN4V43jY8a5XEU_L0SSyWGMV2bs5FiQGr2M,4489
6
7
  turboapi/decorators.py,sha256=jjJrIXZ3y_yJ231ar24hS09OCDtTqmYA7arpIOcr2kk,1788
7
8
  turboapi/main_app.py,sha256=mR-x-RPJn96Jtg0a313hU_2UsLQNV_xNXRtpFYWAr30,9188
@@ -13,4 +14,4 @@ turboapi/rust_integration.py,sha256=ycA_i8kxC2Upbu7PAqC2EdjsqRw5AVkYwLvx9aTWBWc,
13
14
  turboapi/security.py,sha256=-XgwBhiqQZdfU7oKLHi-3xN_UwlKiQxpfSQ6kTA0ko8,17230
14
15
  turboapi/server_integration.py,sha256=drUhhTasWgQfyhFiAaHKd987N3mnE0qkMab1ylmqd4c,18340
15
16
  turboapi/version_check.py,sha256=z3O1vIJsWmG_DO271ayYWSwaDfgpFnfJzYRYyowKYMc,9625
16
- turboapi-0.3.28.dist-info/RECORD,,
17
+ turboapi-0.3.29.dist-info/RECORD,,