libentry 1.11.5__py3-none-any.whl → 1.11.7__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.
libentry/api.py CHANGED
@@ -11,6 +11,7 @@ __all__ = [
11
11
  ]
12
12
 
13
13
  from dataclasses import dataclass, field
14
+ from time import sleep
14
15
  from typing import Any, Callable, Iterable, List, Literal, Mapping, Optional, Tuple
15
16
  from urllib.parse import urljoin
16
17
 
@@ -190,9 +191,44 @@ class APIClient:
190
191
  self.headers["Authorization"] = f"Bearer {api_key}"
191
192
  self.verify = verify
192
193
 
193
- def get(self, path: str, timeout=60):
194
+ def _request(
195
+ self,
196
+ method: str,
197
+ url: str,
198
+ num_trials: int = 5,
199
+ retry_factor: float = 2,
200
+ timeout: float = 5,
201
+ **kwargs
202
+ ):
203
+ err = None
204
+ for _ in range(num_trials):
205
+ try:
206
+ return requests.request(method, url, timeout=timeout, **kwargs)
207
+ except requests.Timeout as e:
208
+ err = e
209
+ except requests.ConnectionError as e:
210
+ err = e
211
+ sleep(timeout)
212
+ timeout *= retry_factor
213
+ raise err
214
+
215
+ def get(
216
+ self,
217
+ path: str,
218
+ num_trials: int = 5,
219
+ retry_factor: float = 2,
220
+ timeout: float = 5
221
+ ):
194
222
  api_url = urljoin(self.base_url, path)
195
- response = requests.get(api_url, headers=self.headers, verify=self.verify, timeout=timeout)
223
+ response = self._request(
224
+ "get",
225
+ url=api_url,
226
+ headers=self.headers,
227
+ verify=self.verify,
228
+ num_trials=num_trials,
229
+ retry_factor=retry_factor,
230
+ timeout=timeout
231
+ )
196
232
 
197
233
  if response.status_code != 200:
198
234
  text = response.text
@@ -208,8 +244,10 @@ class APIClient:
208
244
  self,
209
245
  path: str,
210
246
  json_data: Optional[Mapping] = None,
211
- stream=False,
212
- timeout=60,
247
+ stream: bool = False,
248
+ num_trials: int = 5,
249
+ retry_factor: float = 2,
250
+ timeout: float = 5,
213
251
  chunk_delimiter: str = "\n\n",
214
252
  chunk_prefix: str = None,
215
253
  chunk_suffix: str = None,
@@ -218,12 +256,15 @@ class APIClient:
218
256
  full_url = urljoin(self.base_url, path)
219
257
 
220
258
  data = json.dumps(json_data) if json_data is not None else None
221
- response = requests.post(
222
- full_url,
259
+ response = self._request(
260
+ "post",
261
+ url=full_url,
223
262
  headers=self.headers,
224
263
  data=data,
225
264
  verify=self.verify,
226
265
  stream=stream,
266
+ num_trials=num_trials,
267
+ retry_factor=retry_factor,
227
268
  timeout=timeout
228
269
  )
229
270
  if response.status_code != 200:
libentry/service/flask.py CHANGED
@@ -271,8 +271,10 @@ def run_service(
271
271
  host: str = "0.0.0.0",
272
272
  port: int = 8888,
273
273
  num_workers: int = 1,
274
- num_threads: int = 10,
275
- num_connections: int = 2000,
274
+ num_threads: int = 20,
275
+ num_connections: Optional[int] = 100,
276
+ backlog: Optional[int] = 100,
277
+ worker_class: str = "gthread",
276
278
  timeout: int = 60,
277
279
  keyfile: Optional[str] = None,
278
280
  certfile: Optional[str] = None
@@ -283,9 +285,11 @@ def run_service(
283
285
  "workers": num_workers,
284
286
  "threads": num_threads,
285
287
  "timeout": timeout,
286
- "worker_connections": num_connections,
288
+ "worker_connections": num_connections if num_connections else num_threads,
289
+ "backlog": backlog if backlog else num_threads,
287
290
  "keyfile": keyfile,
288
291
  "certfile": certfile,
292
+ "worker_class": worker_class
289
293
  }
290
294
  for name, value in options.items():
291
295
  logger.info(f"Option {name}: {value}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: libentry
3
- Version: 1.11.5
3
+ Version: 1.11.7
4
4
  Summary: Entries for experimental utilities.
5
5
  Home-page: https://github.com/XoriieInpottn/libentry
6
6
  Author: xi
@@ -1,5 +1,5 @@
1
1
  libentry/__init__.py,sha256=rDBip9M1Xb1N4wMKE1ni_DldrQbkRjp8DxPkTp3K2qo,170
2
- libentry/api.py,sha256=2LWDPP3QJRmwk5WfNI9y57uqjjEQilojlLg6v4pbuPk,8746
2
+ libentry/api.py,sha256=5JI8hEBExxk9VUsYRQ3upCRQ9wrWDgZ8Hv-FdX0KPKA,9820
3
3
  libentry/argparse.py,sha256=Bk11H4WRKxcjMlSd0mjWj1T4NWh0JW5eA7TX3C21IoE,10116
4
4
  libentry/dataclasses.py,sha256=AQV2PuxplJCwGZ5HKX72U-z-POUhTdy3XtpEK9KNIGQ,4541
5
5
  libentry/executor.py,sha256=cTV0WxJi0nU1TP-cOwmeodN8DD6L1691M2HIQsJtGrU,6582
@@ -9,14 +9,14 @@ libentry/logging.py,sha256=IiYoCUzm8XTK1fduA-NA0FI2Qz_m81NEPV3d3tEfgdI,1349
9
9
  libentry/server.py,sha256=gYPoZXd0umlDYZf-6ZV0_vJadg3YQvnLDc6JFDJh9jc,1503
10
10
  libentry/service/__init__.py,sha256=1oLL20yLB1GL9IbFiZD8OReDqiCpFr-yetIR6x1cNkI,23
11
11
  libentry/service/common.py,sha256=OVaW2afgKA6YqstJmtnprBCqQEUZEWotZ6tHavmJJeU,42
12
- libentry/service/flask.py,sha256=jPpOSkxPRz0ma1d-O4zyqbxfy-XrEE2Hku-ccaCADNE,9627
12
+ libentry/service/flask.py,sha256=71FcjawjfoNG4p0hUWyPpiQ8X5Ao4zsTqt_UEbnSMRc,9842
13
13
  libentry/service/list.py,sha256=ElHWhTgShGOhaxMUEwVbMXos0NQKjHsODboiQ-3AMwE,1397
14
14
  libentry/service/running.py,sha256=FrPJoJX6wYxcHIysoatAxhW3LajCCm0Gx6l7__6sULQ,5105
15
15
  libentry/service/start.py,sha256=mZT7b9rVULvzy9GTZwxWnciCHgv9dbGN2JbxM60OMn4,1270
16
16
  libentry/service/stop.py,sha256=wOpwZgrEJ7QirntfvibGq-XsTC6b3ELhzRW2zezh-0s,1187
17
- libentry-1.11.5.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
18
- libentry-1.11.5.dist-info/METADATA,sha256=Mv2rrwKRRvjEE2B8kmkWZe7mRltbbXv8GF3E_DTGKNc,500
19
- libentry-1.11.5.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
20
- libentry-1.11.5.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
21
- libentry-1.11.5.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
22
- libentry-1.11.5.dist-info/RECORD,,
17
+ libentry-1.11.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
18
+ libentry-1.11.7.dist-info/METADATA,sha256=Md151mcRsxn-zEmyISH87ZOV3hSUp1SJeeAirmy-HW0,500
19
+ libentry-1.11.7.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
20
+ libentry-1.11.7.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
21
+ libentry-1.11.7.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
22
+ libentry-1.11.7.dist-info/RECORD,,