cloud-python-vars 0.1.2__tar.gz → 0.2.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloud-python-vars
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: To manage and create raw Python variables on cloud servers.
5
5
  Author-email: ThatOnePythonDev <khakhang2h5e@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: cloud-python-vars
3
- Version: 0.1.2
3
+ Version: 0.2.0
4
4
  Summary: To manage and create raw Python variables on cloud servers.
5
5
  Author-email: ThatOnePythonDev <khakhang2h5e@gmail.com>
6
6
  Classifier: Programming Language :: Python :: 3
@@ -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(0.1)
183
+ time.sleep(self.delay)
174
184
  except Exception as e:
175
- print(e.__traceback__)
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
- print(e.__traceback__)
300
-
301
- asyncio.create_task(task())
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
  """
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "cloud-python-vars"
7
- version = "0.1.2"
7
+ version = "0.2.0"
8
8
  authors = [
9
9
  { name="ThatOnePythonDev", email="khakhang2h5e@gmail.com" },
10
10
  ]