libentry 1.11.5__py3-none-any.whl → 1.11.6__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,48 @@ 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_interval: int = 5,
200
+ retry_factor: float = 2,
201
+ timeout: float = 5,
202
+ **kwargs
203
+ ):
204
+ err = None
205
+ for _ in range(num_trials):
206
+ try:
207
+ return requests.request(method, url, timeout=timeout, **kwargs)
208
+ except requests.Timeout as e:
209
+ err = e
210
+ except requests.ConnectionError as e:
211
+ err = e
212
+ sleep(retry_interval)
213
+ timeout *= retry_factor
214
+ retry_interval *= retry_factor
215
+ raise err
216
+
217
+ def get(
218
+ self,
219
+ path: str,
220
+ num_trials: int = 5,
221
+ retry_interval: int = 5,
222
+ retry_factor: float = 2,
223
+ timeout: float = 5
224
+ ):
194
225
  api_url = urljoin(self.base_url, path)
195
- response = requests.get(api_url, headers=self.headers, verify=self.verify, timeout=timeout)
226
+ response = self._request(
227
+ "get",
228
+ url=api_url,
229
+ headers=self.headers,
230
+ verify=self.verify,
231
+ num_trials=num_trials,
232
+ retry_interval=retry_interval,
233
+ retry_factor=retry_factor,
234
+ timeout=timeout
235
+ )
196
236
 
197
237
  if response.status_code != 200:
198
238
  text = response.text
@@ -208,8 +248,11 @@ class APIClient:
208
248
  self,
209
249
  path: str,
210
250
  json_data: Optional[Mapping] = None,
211
- stream=False,
212
- timeout=60,
251
+ stream: bool = False,
252
+ num_trials: int = 5,
253
+ retry_interval: int = 5,
254
+ retry_factor: float = 2,
255
+ timeout: float = 5,
213
256
  chunk_delimiter: str = "\n\n",
214
257
  chunk_prefix: str = None,
215
258
  chunk_suffix: str = None,
@@ -218,12 +261,16 @@ class APIClient:
218
261
  full_url = urljoin(self.base_url, path)
219
262
 
220
263
  data = json.dumps(json_data) if json_data is not None else None
221
- response = requests.post(
222
- full_url,
264
+ response = self._request(
265
+ "post",
266
+ url=full_url,
223
267
  headers=self.headers,
224
268
  data=data,
225
269
  verify=self.verify,
226
270
  stream=stream,
271
+ num_trials=num_trials,
272
+ retry_interval=retry_interval,
273
+ retry_factor=retry_factor,
227
274
  timeout=timeout
228
275
  )
229
276
  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.6
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=IajZ1oSSsFfB7Gc4QUCGy8uUqxrtFov1LTsMg06ck0Y,10067
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.6.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
18
+ libentry-1.11.6.dist-info/METADATA,sha256=pQ_nA2SJrcmSEX-_y-ljBsTP3C7j70onmqtU8IWXFeY,500
19
+ libentry-1.11.6.dist-info/WHEEL,sha256=OqRkF0eY5GHssMorFjlbTIq072vpHpF60fIQA6lS9xA,92
20
+ libentry-1.11.6.dist-info/top_level.txt,sha256=u2uF6-X5fn2Erf9PYXOg_6tntPqTpyT-yzUZrltEd6I,9
21
+ libentry-1.11.6.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
22
+ libentry-1.11.6.dist-info/RECORD,,