cloud-python-vars 0.1.2__py3-none-any.whl → 0.2.0__py3-none-any.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.
- {cloud_python_vars-0.1.2.dist-info → cloud_python_vars-0.2.0.dist-info}/METADATA +1 -1
- cloud_python_vars-0.2.0.dist-info/RECORD +6 -0
- cloud_variables.py +37 -10
- cloud_python_vars-0.1.2.dist-info/RECORD +0 -6
- {cloud_python_vars-0.1.2.dist-info → cloud_python_vars-0.2.0.dist-info}/WHEEL +0 -0
- {cloud_python_vars-0.1.2.dist-info → cloud_python_vars-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {cloud_python_vars-0.1.2.dist-info → cloud_python_vars-0.2.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
cloud_variables.py,sha256=5Yfsd697M9hZG0fvk7eiGglknHVx57HzFf_akPjJNpI,12359
|
|
2
|
+
cloud_python_vars-0.2.0.dist-info/licenses/LICENSE,sha256=QrYZJWmrewKHOtQwd1ymTUDpPzhnXt9Fhv6PGf-JfGs,35788
|
|
3
|
+
cloud_python_vars-0.2.0.dist-info/METADATA,sha256=7hQbkTHZZC7MIM3Ifd9d_erQFg0aG237e-pCnqAxpUE,3088
|
|
4
|
+
cloud_python_vars-0.2.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
+
cloud_python_vars-0.2.0.dist-info/top_level.txt,sha256=DxTkZ9m7oYGS873O2K7iiP6cP4t0LRqo9jL1wn-Voog,16
|
|
6
|
+
cloud_python_vars-0.2.0.dist-info/RECORD,,
|
cloud_variables.py
CHANGED
|
@@ -96,11 +96,11 @@ async def main() -> None: # You're recommended to put this in an asynchronous fu
|
|
|
96
96
|
|
|
97
97
|
from __future__ import annotations
|
|
98
98
|
|
|
99
|
-
from typing import Any, Literal, Never
|
|
100
|
-
|
|
101
|
-
import time
|
|
102
99
|
import asyncio
|
|
103
100
|
import threading
|
|
101
|
+
import time
|
|
102
|
+
from typing import Any, Literal, override
|
|
103
|
+
|
|
104
104
|
import upstash_redis as redis
|
|
105
105
|
|
|
106
106
|
|
|
@@ -120,6 +120,7 @@ class CloudProxy:
|
|
|
120
120
|
|
|
121
121
|
self.value: Any = value
|
|
122
122
|
|
|
123
|
+
@override
|
|
123
124
|
def __repr__(self) -> str:
|
|
124
125
|
return f"CloudProxy({self.value})"
|
|
125
126
|
|
|
@@ -137,6 +138,8 @@ class CloudVar(redis.Redis):
|
|
|
137
138
|
rest_retry_interval: float = 3,
|
|
138
139
|
allow_telemetry: bool = True,
|
|
139
140
|
read_your_writes: bool = True,
|
|
141
|
+
delay: float = 0.1,
|
|
142
|
+
tb: Literal["strict", "log", "ignore"] = "log"
|
|
140
143
|
) -> None:
|
|
141
144
|
"""
|
|
142
145
|
To initialize the class.
|
|
@@ -148,6 +151,8 @@ class CloudVar(redis.Redis):
|
|
|
148
151
|
:param rest_retry_interval: The number of seconds the client waits before retrying a new request. The default is 3.
|
|
149
152
|
:param allow_telemetry: Controls whether the client is allowed to send telemetry data. The default is True.
|
|
150
153
|
:param read_your_writes: Allows whether the client is allowed to read your writes. The default is True.
|
|
154
|
+
:param delay: The delay to prevent CPU over-usage and network spamming. The default is 0.1.
|
|
155
|
+
:param tb: Controls what to do when an error occurs. 'strict' for letting it raise, 'log' for catching and logging the error, 'ignore' for passing silently. The default is 'log'.
|
|
151
156
|
|
|
152
157
|
:type url: str
|
|
153
158
|
:type token: str
|
|
@@ -156,6 +161,8 @@ class CloudVar(redis.Redis):
|
|
|
156
161
|
:type rest_retry_interval: float
|
|
157
162
|
:type allow_telemetry: bool
|
|
158
163
|
:type read_your_writes: bool
|
|
164
|
+
:type delay: float
|
|
165
|
+
:type tb: Literal["strict", "log", "ignore"]
|
|
159
166
|
"""
|
|
160
167
|
|
|
161
168
|
super().__init__(url, token, rest_encoding, rest_retries, rest_retry_interval, allow_telemetry, read_your_writes,)
|
|
@@ -165,14 +172,23 @@ class CloudVar(redis.Redis):
|
|
|
165
172
|
self.__thread: threading.Thread = threading.Thread(target=self.__loop)
|
|
166
173
|
self.__thread.start()
|
|
167
174
|
|
|
175
|
+
self.delay: float = delay
|
|
176
|
+
self.tb: str = tb
|
|
177
|
+
|
|
168
178
|
def __loop(self) -> None:
|
|
169
179
|
try:
|
|
170
180
|
while True:
|
|
171
181
|
for k, v in self.__data.copy().items():
|
|
172
182
|
self.set(k, repr(v))
|
|
173
|
-
time.sleep(
|
|
183
|
+
time.sleep(self.delay)
|
|
174
184
|
except Exception as e:
|
|
175
|
-
|
|
185
|
+
match self.tb:
|
|
186
|
+
case "strict":
|
|
187
|
+
raise
|
|
188
|
+
case "log":
|
|
189
|
+
print(e.__traceback__)
|
|
190
|
+
case _:
|
|
191
|
+
pass
|
|
176
192
|
|
|
177
193
|
def __setitem__(self, key: str, value: Any) -> None:
|
|
178
194
|
"""
|
|
@@ -221,7 +237,7 @@ class CloudVar(redis.Redis):
|
|
|
221
237
|
|
|
222
238
|
for key in keys:
|
|
223
239
|
del self.__data[key]
|
|
224
|
-
|
|
240
|
+
|
|
225
241
|
return tuple(values)
|
|
226
242
|
|
|
227
243
|
def clear(self) -> None:
|
|
@@ -259,6 +275,8 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
259
275
|
rest_retry_interval: float = 3,
|
|
260
276
|
allow_telemetry: bool = True,
|
|
261
277
|
read_your_writes: bool = True,
|
|
278
|
+
delay: float = 0.1,
|
|
279
|
+
tb: Literal["strict", "log", "ignore"] = "log"
|
|
262
280
|
) -> None:
|
|
263
281
|
"""
|
|
264
282
|
To initialize the class.
|
|
@@ -284,6 +302,9 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
284
302
|
|
|
285
303
|
self.__data: dict[str, CloudProxy] = {}
|
|
286
304
|
|
|
305
|
+
self.delay: float = delay
|
|
306
|
+
self.tb: str = tb
|
|
307
|
+
|
|
287
308
|
def start(self) -> None:
|
|
288
309
|
"""Starts the instance's process."""
|
|
289
310
|
|
|
@@ -293,12 +314,18 @@ class AsyncCloudVar(redis.AsyncRedis):
|
|
|
293
314
|
try:
|
|
294
315
|
while True:
|
|
295
316
|
for k, v in self.__data.copy().items():
|
|
296
|
-
await self.set(k, repr(v))
|
|
317
|
+
_ = await self.set(k, repr(v))
|
|
297
318
|
await asyncio.sleep(0.1)
|
|
298
319
|
except Exception as e:
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
320
|
+
match self.tb:
|
|
321
|
+
case "strict":
|
|
322
|
+
raise
|
|
323
|
+
case "log":
|
|
324
|
+
print(e.__traceback__)
|
|
325
|
+
case _:
|
|
326
|
+
pass
|
|
327
|
+
|
|
328
|
+
_ = asyncio.create_task(task())
|
|
302
329
|
|
|
303
330
|
def __setitem__(self, key: str, value: Any) -> None:
|
|
304
331
|
"""
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
cloud_variables.py,sha256=X2YBZJUtCvx3DkCH6dJ3ZlIPzcQJEKIzbUXPmPEb1fc,11291
|
|
2
|
-
cloud_python_vars-0.1.2.dist-info/licenses/LICENSE,sha256=QrYZJWmrewKHOtQwd1ymTUDpPzhnXt9Fhv6PGf-JfGs,35788
|
|
3
|
-
cloud_python_vars-0.1.2.dist-info/METADATA,sha256=B1H1ZIj-YM5Ypea998mHPwXN8h9MlVM7tNW2dREixm4,3088
|
|
4
|
-
cloud_python_vars-0.1.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
5
|
-
cloud_python_vars-0.1.2.dist-info/top_level.txt,sha256=DxTkZ9m7oYGS873O2K7iiP6cP4t0LRqo9jL1wn-Voog,16
|
|
6
|
-
cloud_python_vars-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|