resourcecap 0.2.2__tar.gz → 0.2.4__tar.gz
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.
- {resourcecap-0.2.2 → resourcecap-0.2.4}/PKG-INFO +14 -1
- {resourcecap-0.2.2 → resourcecap-0.2.4}/README.md +11 -0
- {resourcecap-0.2.2 → resourcecap-0.2.4}/pyproject.toml +3 -1
- {resourcecap-0.2.2 → resourcecap-0.2.4}/pyproject.toml.orig +3 -1
- {resourcecap-0.2.2 → resourcecap-0.2.4}/src/resourcecap/_budget.py +14 -4
- {resourcecap-0.2.2 → resourcecap-0.2.4}/src/resourcecap/__init__.py +0 -0
- {resourcecap-0.2.2 → resourcecap-0.2.4}/src/resourcecap/_costs.py +0 -0
- {resourcecap-0.2.2 → resourcecap-0.2.4}/src/resourcecap/_resources.py +0 -0
- {resourcecap-0.2.2 → resourcecap-0.2.4}/src/resourcecap/_tracking.py +0 -0
- {resourcecap-0.2.2 → resourcecap-0.2.4}/src/resourcecap/py.typed +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: resourcecap
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A python package to limit the resource usage of any program
|
|
5
5
|
Author: purushottam-dafure
|
|
6
6
|
Author-email: purushottam-dafure <purushottamdafure@gmail.com>
|
|
7
7
|
License-Expression: MIT
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
10
12
|
Classifier: Operating System :: OS Independent
|
|
11
13
|
Classifier: Typing :: Typed
|
|
12
14
|
Requires-Python: >=3.12
|
|
@@ -97,6 +99,17 @@ Each call to `foo()` logs something like:
|
|
|
97
99
|
the above code will stop execution at that point and raise BudgetExhaustedError,
|
|
98
100
|
after the 4th call to `foo()` pushes the spend from 30 to 40.
|
|
99
101
|
|
|
102
|
+
`BudgetExhaustedError` carries structured fields, not just a message, so you
|
|
103
|
+
can handle it programmatically without parsing text:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
try:
|
|
107
|
+
with Budget(amount = 30):
|
|
108
|
+
[foo() for i in range(5)]
|
|
109
|
+
except BudgetExhaustedError as e:
|
|
110
|
+
print(e.resource, e.limit, e.spent) # "cost" 30 40.0
|
|
111
|
+
```
|
|
112
|
+
|
|
100
113
|
A `Budget` instance can be reused across separate, non-overlapping `with`
|
|
101
114
|
blocks (its spend resets each time), but it can't be open twice at once —
|
|
102
115
|
entering it while it's already open, from a concurrent task/thread or
|
|
@@ -83,6 +83,17 @@ Each call to `foo()` logs something like:
|
|
|
83
83
|
the above code will stop execution at that point and raise BudgetExhaustedError,
|
|
84
84
|
after the 4th call to `foo()` pushes the spend from 30 to 40.
|
|
85
85
|
|
|
86
|
+
`BudgetExhaustedError` carries structured fields, not just a message, so you
|
|
87
|
+
can handle it programmatically without parsing text:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
try:
|
|
91
|
+
with Budget(amount = 30):
|
|
92
|
+
[foo() for i in range(5)]
|
|
93
|
+
except BudgetExhaustedError as e:
|
|
94
|
+
print(e.resource, e.limit, e.spent) # "cost" 30 40.0
|
|
95
|
+
```
|
|
96
|
+
|
|
86
97
|
A `Budget` instance can be reused across separate, non-overlapping `with`
|
|
87
98
|
blocks (its spend resets each time), but it can't be open twice at once —
|
|
88
99
|
entering it while it's already open, from a concurrent task/thread or
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "resourcecap"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.4"
|
|
4
4
|
description = "A python package to limit the resource usage of any program"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -9,6 +9,8 @@ dependencies = []
|
|
|
9
9
|
classifiers = [
|
|
10
10
|
"Programming Language :: Python :: 3",
|
|
11
11
|
"Programming Language :: Python :: 3.12",
|
|
12
|
+
"Programming Language :: Python :: 3.13",
|
|
13
|
+
"Programming Language :: Python :: 3.14",
|
|
12
14
|
"Operating System :: OS Independent",
|
|
13
15
|
"Typing :: Typed",
|
|
14
16
|
]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "resourcecap"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.4"
|
|
4
4
|
description = "A python package to limit the resource usage of any program"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
license = "MIT"
|
|
@@ -12,6 +12,8 @@ dependencies = []
|
|
|
12
12
|
classifiers = [
|
|
13
13
|
"Programming Language :: Python :: 3",
|
|
14
14
|
"Programming Language :: Python :: 3.12",
|
|
15
|
+
"Programming Language :: Python :: 3.13",
|
|
16
|
+
"Programming Language :: Python :: 3.14",
|
|
15
17
|
"Operating System :: OS Independent",
|
|
16
18
|
"Typing :: Typed",
|
|
17
19
|
]
|
|
@@ -11,7 +11,19 @@ logger = logging.getLogger("resourcecap")
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
class BudgetExhaustedError(Exception):
|
|
14
|
-
"""Raised when a `Budget`'s limit for some resource is exceeded.
|
|
14
|
+
"""Raised when a `Budget`'s limit for some resource is exceeded.
|
|
15
|
+
|
|
16
|
+
Attributes:
|
|
17
|
+
resource: the key of the resource whose limit was exceeded.
|
|
18
|
+
limit: that resource's limit.
|
|
19
|
+
spent: how much had been spent when the limit was exceeded.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def __init__(self, resource: Hashable, limit: float, spent: float) -> None:
|
|
23
|
+
super().__init__(f"budget for resource {resource!r} of {limit} exhausted: spent {spent}")
|
|
24
|
+
self.resource = resource
|
|
25
|
+
self.limit = limit
|
|
26
|
+
self.spent = spent
|
|
15
27
|
|
|
16
28
|
|
|
17
29
|
class BudgetReentryError(RuntimeError):
|
|
@@ -100,9 +112,7 @@ class Budget:
|
|
|
100
112
|
"resource=%s limit=%s exhausted: spent=%s", key, limit.amount, spent
|
|
101
113
|
)
|
|
102
114
|
else:
|
|
103
|
-
raise BudgetExhaustedError(
|
|
104
|
-
f"budget for resource {key!r} of {limit.amount} exhausted: spent {spent}"
|
|
105
|
-
)
|
|
115
|
+
raise BudgetExhaustedError(key, limit.amount, spent)
|
|
106
116
|
|
|
107
117
|
def __enter__(self) -> "Budget":
|
|
108
118
|
with self._lock:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|