MeUtils 2024.12.5.15.58.45__py3-none-any.whl → 2024.12.5.17.36.18__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.
- {MeUtils-2024.12.5.15.58.45.dist-info → MeUtils-2024.12.5.17.36.18.dist-info}/METADATA +28 -28
- {MeUtils-2024.12.5.15.58.45.dist-info → MeUtils-2024.12.5.17.36.18.dist-info}/RECORD +11 -11
- meutils/apis/hunyuan/image_tools.py +11 -5
- meutils/apis/proxy/ips.py +12 -10
- meutils/apis/textin.py +18 -18
- meutils/data/VERSION +1 -1
- meutils/decorators/retry.py +55 -20
- {MeUtils-2024.12.5.15.58.45.dist-info → MeUtils-2024.12.5.17.36.18.dist-info}/LICENSE +0 -0
- {MeUtils-2024.12.5.15.58.45.dist-info → MeUtils-2024.12.5.17.36.18.dist-info}/WHEEL +0 -0
- {MeUtils-2024.12.5.15.58.45.dist-info → MeUtils-2024.12.5.17.36.18.dist-info}/entry_points.txt +0 -0
- {MeUtils-2024.12.5.15.58.45.dist-info → MeUtils-2024.12.5.17.36.18.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: MeUtils
|
3
|
-
Version: 2024.12.5.
|
3
|
+
Version: 2024.12.5.17.36.18
|
4
4
|
Summary: description
|
5
5
|
Home-page: https://github.com/yuanjie-ai/MeUtils
|
6
6
|
Author: yuanjie
|
@@ -61,42 +61,42 @@ Requires-Dist: sse-starlette ; extra == 'ai'
|
|
61
61
|
Requires-Dist: openai ; extra == 'ai'
|
62
62
|
Requires-Dist: langchain ; extra == 'ai'
|
63
63
|
Provides-Extra: all
|
64
|
-
Requires-Dist:
|
65
|
-
Requires-Dist: streamlit ; extra == 'all'
|
66
|
-
Requires-Dist: pymupd ; extra == 'all'
|
67
|
-
Requires-Dist: jieba ; extra == 'all'
|
68
|
-
Requires-Dist: jinja2 ; extra == 'all'
|
64
|
+
Requires-Dist: openai ; extra == 'all'
|
69
65
|
Requires-Dist: geopy ; extra == 'all'
|
70
|
-
Requires-Dist:
|
71
|
-
Requires-Dist: seaborn ; extra == 'all'
|
66
|
+
Requires-Dist: pandas-profiling[notebook] ; extra == 'all'
|
72
67
|
Requires-Dist: pymilvus ; extra == 'all'
|
73
|
-
Requires-Dist:
|
74
|
-
Requires-Dist:
|
75
|
-
Requires-Dist:
|
76
|
-
Requires-Dist: thriftpy2 ; extra == 'all'
|
77
|
-
Requires-Dist: gunicorn ; extra == 'all'
|
78
|
-
Requires-Dist: redis-py-cluster ; extra == 'all'
|
79
|
-
Requires-Dist: faiss-cpu ; extra == 'all'
|
68
|
+
Requires-Dist: iteration-utilities ; extra == 'all'
|
69
|
+
Requires-Dist: pymupd ; extra == 'all'
|
70
|
+
Requires-Dist: thefuck ; extra == 'all'
|
80
71
|
Requires-Dist: uvicorn ; extra == 'all'
|
81
|
-
Requires-Dist:
|
72
|
+
Requires-Dist: faiss-cpu ; extra == 'all'
|
73
|
+
Requires-Dist: jmespath ; extra == 'all'
|
82
74
|
Requires-Dist: langchain ; extra == 'all'
|
83
|
-
Requires-Dist:
|
84
|
-
Requires-Dist: iteration-utilities ; extra == 'all'
|
85
|
-
Requires-Dist: openai ; extra == 'all'
|
86
|
-
Requires-Dist: fastapi[all] ; extra == 'all'
|
87
|
-
Requires-Dist: cachetools ; extra == 'all'
|
88
|
-
Requires-Dist: filetype ; extra == 'all'
|
89
|
-
Requires-Dist: sse-starlette ; extra == 'all'
|
90
|
-
Requires-Dist: pymysql ; extra == 'all'
|
75
|
+
Requires-Dist: sqlalchemy ; extra == 'all'
|
91
76
|
Requires-Dist: missingno ; extra == 'all'
|
77
|
+
Requires-Dist: gunicorn ; extra == 'all'
|
78
|
+
Requires-Dist: polars ; extra == 'all'
|
79
|
+
Requires-Dist: jieba ; extra == 'all'
|
80
|
+
Requires-Dist: fastapi[all] ; extra == 'all'
|
81
|
+
Requires-Dist: asyncmy ; extra == 'all'
|
82
|
+
Requires-Dist: pyarrow ; extra == 'all'
|
83
|
+
Requires-Dist: streamlit ; extra == 'all'
|
92
84
|
Requires-Dist: reportlab ; extra == 'all'
|
85
|
+
Requires-Dist: fastapi ; extra == 'all'
|
93
86
|
Requires-Dist: dataframe-image ; extra == 'all'
|
87
|
+
Requires-Dist: pandas-summary ; extra == 'all'
|
88
|
+
Requires-Dist: pymysql ; extra == 'all'
|
89
|
+
Requires-Dist: simplejson ; extra == 'all'
|
90
|
+
Requires-Dist: seaborn ; extra == 'all'
|
91
|
+
Requires-Dist: thriftpy2 ; extra == 'all'
|
92
|
+
Requires-Dist: redis-py-cluster ; extra == 'all'
|
94
93
|
Requires-Dist: pymongo ; extra == 'all'
|
94
|
+
Requires-Dist: pretty-errors ; extra == 'all'
|
95
|
+
Requires-Dist: sse-starlette ; extra == 'all'
|
96
|
+
Requires-Dist: jinja2 ; extra == 'all'
|
97
|
+
Requires-Dist: cachetools ; extra == 'all'
|
98
|
+
Requires-Dist: filetype ; extra == 'all'
|
95
99
|
Requires-Dist: schedule ; extra == 'all'
|
96
|
-
Requires-Dist: pyarrow ; extra == 'all'
|
97
|
-
Requires-Dist: asyncmy ; extra == 'all'
|
98
|
-
Requires-Dist: jmespath ; extra == 'all'
|
99
|
-
Requires-Dist: thefuck ; extra == 'all'
|
100
100
|
Provides-Extra: ann
|
101
101
|
Requires-Dist: pymilvus ; extra == 'ann'
|
102
102
|
Requires-Dist: faiss-cpu ; extra == 'ann'
|
@@ -295,7 +295,7 @@ meutils/apis/kuaidi.py,sha256=4KrtOkbGlsLpyvbY80UMSo03iFqFiBHnE0CiqAWWQ4Y,998
|
|
295
295
|
meutils/apis/llm_qa.py,sha256=XM1VMkOTb4xKzgVk56dPC1e8lg7SbnfobBVgfLXiX9A,1207
|
296
296
|
meutils/apis/niutrans.py,sha256=weWjn-tUTEaAUe5RGbzcjQqPkJxGDrPwMB6CnaiZSsg,1682
|
297
297
|
meutils/apis/search_music.py,sha256=HBLtdterztrccnLAPZrWBlrYSx4WCRflCqz-V30fOA8,972
|
298
|
-
meutils/apis/textin.py,sha256=
|
298
|
+
meutils/apis/textin.py,sha256=6j0aBxhgpFfduGI13Rw9Lmd3d7a631XqopA9eDrNDX8,4867
|
299
299
|
meutils/apis/ts.py,sha256=Q13EOS9Q-Y2-KwOG_cFMVmGj9RUmDtxk5A3E27dxbN0,1511
|
300
300
|
meutils/apis/web_search.py,sha256=6gS3leIB2iyeLtqhB0IbpL_mKzDgArRTqnR7odTWT3E,1035
|
301
301
|
meutils/apis/yezi.py,sha256=26vhnA3lC5049Rqx-CHO-wyGKbdZAfvjEOG90W38cr0,3675
|
@@ -328,7 +328,7 @@ meutils/apis/hf/r.py,sha256=jvD0WBM5dEZGG4rfdGZnUIh2W9sv-fqTFo-8ouLea60,1272
|
|
328
328
|
meutils/apis/hf/x.py,sha256=QYLiTlTZk1b0wczGHeJMjQABQUQmI_Wk45gbCcCAdIc,862
|
329
329
|
meutils/apis/hf/证件照.py,sha256=NVfFp-wO1YCpvf7ClInK-jVJO9atZuk9VN93GrPohoc,1262
|
330
330
|
meutils/apis/hunyuan/__init__.py,sha256=vJg28p4USaiGt3vAPKurjuxTPtk_LdmThw3cNc48vpI,272
|
331
|
-
meutils/apis/hunyuan/image_tools.py,sha256=
|
331
|
+
meutils/apis/hunyuan/image_tools.py,sha256=5y93jzU2B4O3JUE1nWBSuhUJCY8zLeiT0BLGdwpYaCo,2550
|
332
332
|
meutils/apis/images/__init__.py,sha256=hs7HUJZvw_3DAtoapPnbZsEb4ng1p0a6fJGFFWwUcUk,272
|
333
333
|
meutils/apis/images/deepinfra.py,sha256=N7IDJ9dubojOY--R30uQlzSBbuuy4OXkCkRB1ey0kcQ,3241
|
334
334
|
meutils/apis/images/demo.py,sha256=Cjk-EKMKbp44czykW_44qR0TzElX8nNCALqXBBw5sJA,4405
|
@@ -376,7 +376,7 @@ meutils/apis/oneapi/user.py,sha256=Q4FhUwuUZlOpe9qh8P4ioTnGX3cEtBae39bSMciWDA8,3
|
|
376
376
|
meutils/apis/pixverse/__init__.py,sha256=WiboEUfJ_3Hs2WI3OymEspx8_ZSTgMglxTJd97Qk7qo,271
|
377
377
|
meutils/apis/pixverse/pixverse.py,sha256=dvnyYVUXCEY_cLnmX9lvq9TesvplCMCuJmmP7ShchQk,5534
|
378
378
|
meutils/apis/proxy/__init__.py,sha256=by7_6GT3xeDjAWLLqbw8uvGaZ3RdprEW-zJ2DFLOdwA,271
|
379
|
-
meutils/apis/proxy/ips.py,sha256=
|
379
|
+
meutils/apis/proxy/ips.py,sha256=gdnzX7BUuraU4Vpr8l0t1liw9Z6Ow3ZAe7D6wkWk01c,5339
|
380
380
|
meutils/apis/remini/__init__.py,sha256=8TbAnbI_bDfH8g0Y9EHXHBum7C0rZt9MzgAAz_MbAeI,271
|
381
381
|
meutils/apis/remini/remini.py,sha256=bJjvtqrCNlAu7No4gYGjoWAM0ch6dCsofYSy2jPZrXg,4239
|
382
382
|
meutils/apis/replicateai/__init__.py,sha256=PK7e7-xhn5aj5WOyGHLzpsHQvpeM5uTOiMylvj40ZmU,272
|
@@ -466,7 +466,7 @@ meutils/config_utils/lark_utils/demo.py,sha256=3g0Fs7oLaeW75T60gYWMLgyNg1OnfOjfH
|
|
466
466
|
meutils/config_utils/lark_utils/x.py,sha256=MlMQGhehP9xMEgetxVCX68XFaosfKoW1JA5cZ3JqN2w,1857
|
467
467
|
meutils/crawlers/__init__.py,sha256=TBU4xA-IOsHV-0yIkW7YXxn_QT7TT8NncqxO7IykEfs,271
|
468
468
|
meutils/data/SimHei.ttf,sha256=-XEnekS5yHP_URkT4XBI2w22ylV-KxudhkeIYFbrILA,10062565
|
469
|
-
meutils/data/VERSION,sha256=
|
469
|
+
meutils/data/VERSION,sha256=h8fEMh2gMBwxWG4H4NJxSMgC5u83FZ9NORoJX3KasgA,19
|
470
470
|
meutils/data/_FLAG,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
471
471
|
meutils/data/_SUCCESS,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
472
472
|
meutils/data/__init__.py,sha256=Hfwkkxs4zHqKhxht0YrhS566a9P5axtmgNvM5wF8ceQ,243
|
@@ -491,7 +491,7 @@ meutils/decorators/decorator_demo.py,sha256=JLCulTW04uYHzLg6jRxVseaAdU-YeyL8Z2p-
|
|
491
491
|
meutils/decorators/demo.py,sha256=EZ9uYz5zGdAqUxa9l2C8gTZqdjY5Uw2uZsAUa9tZXq0,710
|
492
492
|
meutils/decorators/fastapi_decorator.py,sha256=TH5XtzALxDOFVJsK9XMx9xwV9_n9u7cGa9pwHUR218Q,3428
|
493
493
|
meutils/decorators/feishu.py,sha256=0mJSJXIQSc2qYafZzeDPb6XhH6fL8u0pUI9bhOljn1M,3634
|
494
|
-
meutils/decorators/retry.py,sha256=
|
494
|
+
meutils/decorators/retry.py,sha256=PV42YxBzzf5r8MKjzfkSyV3r6JiH9R_OBIo_1W2tPqg,6242
|
495
495
|
meutils/decorators/scheduler.py,sha256=NHeUXABx8YpHbxASqAJWEKa3i1AcyvIGcUW461glYKY,1678
|
496
496
|
meutils/decorators/schedulers.py,sha256=pZrqMVXl7levZdUgUYHfjwA8oJIPJvbVcQw5CwhuiWU,2664
|
497
497
|
meutils/easy_search/__init__.py,sha256=ZWP75-HhKeyckGGR7M_dOXPjuY9PjWDl_bLhZOes0g0,242
|
@@ -801,9 +801,9 @@ meutils/tools/seize.py,sha256=nOKAS63w-Lbi48I0m2MPhdsokUTwxco0laPxYVmW4Mw,1064
|
|
801
801
|
meutils/tools/service_monitor.py,sha256=ibsLtBN2g2DL7ZnLJ8vhiZOiOcqTAyx711djDdBK-3M,1255
|
802
802
|
meutils/tools/sys_monitor.py,sha256=6MoyzrItqDUOSjfHcMJmMofQkEPTW36CT_aKui0rg84,429
|
803
803
|
meutils/tools/token_monitor.py,sha256=Np-YK-R4P4IPAXyZvMxwvXI4sFmNJQAQK1lSegNaYpA,997
|
804
|
-
MeUtils-2024.12.5.
|
805
|
-
MeUtils-2024.12.5.
|
806
|
-
MeUtils-2024.12.5.
|
807
|
-
MeUtils-2024.12.5.
|
808
|
-
MeUtils-2024.12.5.
|
809
|
-
MeUtils-2024.12.5.
|
804
|
+
MeUtils-2024.12.5.17.36.18.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
805
|
+
MeUtils-2024.12.5.17.36.18.dist-info/METADATA,sha256=5DREhdZbj1QqcUYBeCanVPJ0wydI6PbCMjmZpiMhgnQ,6143
|
806
|
+
MeUtils-2024.12.5.17.36.18.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
807
|
+
MeUtils-2024.12.5.17.36.18.dist-info/entry_points.txt,sha256=lufZlBHRqqZKdY-ZQJ4CSZb0qhV5hQC37egZna9M7ug,357
|
808
|
+
MeUtils-2024.12.5.17.36.18.dist-info/top_level.txt,sha256=cInfxMmkgNOskurdjwP5unau4rA7Uw48nu07tYhS7KY,22
|
809
|
+
MeUtils-2024.12.5.17.36.18.dist-info/RECORD,,
|
@@ -10,7 +10,7 @@
|
|
10
10
|
import json_repair
|
11
11
|
|
12
12
|
from meutils.pipe import *
|
13
|
-
from meutils.decorators.retry import retrying
|
13
|
+
from meutils.decorators.retry import retrying, IgnoredRetryException
|
14
14
|
from meutils.schemas.yuanbao_types import FEISHU_URL, YUANBAO_BASE_URL
|
15
15
|
from meutils.schemas.image_types import HunyuanImageProcessRequest
|
16
16
|
|
@@ -18,7 +18,7 @@ from meutils.config_utils.lark_utils import get_next_token_for_polling
|
|
18
18
|
from meutils.io.files_utils import to_url
|
19
19
|
|
20
20
|
|
21
|
-
@retrying(min=3)
|
21
|
+
@retrying(min=3, ignored_exception_types=(IgnoredRetryException,))
|
22
22
|
async def image_process(request: HunyuanImageProcessRequest, token: Optional[str] = None):
|
23
23
|
token = token or await get_next_token_for_polling(FEISHU_URL)
|
24
24
|
|
@@ -39,10 +39,15 @@ async def image_process(request: HunyuanImageProcessRequest, token: Optional[str
|
|
39
39
|
response.raise_for_status()
|
40
40
|
logger.debug(response.text)
|
41
41
|
|
42
|
-
data
|
43
|
-
|
42
|
+
data = json_repair.repair_json(response.text.replace(r'\u0026', '&'), return_objects=True)[-2]
|
43
|
+
|
44
|
+
# todo: 错误处理
|
45
|
+
if isinstance(data, dict) and any(data["code"] == code for code in {"429"}):
|
44
46
|
Exception("重试")
|
45
47
|
|
48
|
+
elif any(i in response.text for i in {"当前图片没有检测到水印"}): # 跳过重试并返回原始错误
|
49
|
+
raise IgnoredRetryException(data)
|
50
|
+
|
46
51
|
data = {
|
47
52
|
"data": [
|
48
53
|
{
|
@@ -61,6 +66,7 @@ if __name__ == '__main__':
|
|
61
66
|
|
62
67
|
with timer():
|
63
68
|
image = "https://sfile.chatglm.cn/chatglm4/3dcb1cc2-22ad-420b-9d16-dc71dffc02b2.png"
|
64
|
-
|
69
|
+
image = "https://oss.ffire.cc/files/kling_watermark.png"
|
70
|
+
request = HunyuanImageProcessRequest(image=image, task='removewatermark')
|
65
71
|
|
66
72
|
arun(image_process(request))
|
meutils/apis/proxy/ips.py
CHANGED
@@ -36,12 +36,15 @@ async def get_one_proxy(token: Optional[str] = None, feishu_url: str = "", from_
|
|
36
36
|
else:
|
37
37
|
# 随机获取ip: 如果从redis就是循环队列 check_proxy
|
38
38
|
ip = await get_next_token_for_polling(feishu_url, from_redis=from_redis)
|
39
|
+
# https://github.com/encode/httpx/pull/2879
|
40
|
+
# proxies = {
|
41
|
+
# "http://": f"http://{ip}", # 自建 38443
|
42
|
+
# "https://": f"http://{ip}",
|
43
|
+
# }
|
39
44
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
}
|
44
|
-
return proxies
|
45
|
+
proxy = f"http://{ip}"
|
46
|
+
|
47
|
+
return proxy
|
45
48
|
|
46
49
|
|
47
50
|
def checkip(): # 获取本地ip
|
@@ -154,12 +157,11 @@ if __name__ == '__main__':
|
|
154
157
|
#
|
155
158
|
# logger.debug(resp.text)
|
156
159
|
ip = "http://proxy.chatfire.cn"
|
157
|
-
ip="http://chatfire:chatfire@110.42.51.201:38443"
|
158
|
-
ip="http://154.9.253.9:38443"
|
160
|
+
ip = "http://chatfire:chatfire@110.42.51.201:38443"
|
161
|
+
ip = "http://154.9.253.9:38443"
|
159
162
|
ip = "http://154.9.252.28:38443"
|
160
|
-
ip="http://110.42.51.223:38443"
|
161
|
-
ip="http://154.40.54.76:38443"
|
162
|
-
|
163
|
+
ip = "http://110.42.51.223:38443"
|
164
|
+
ip = "http://154.40.54.76:38443"
|
163
165
|
|
164
166
|
proxies = {'http://': ip, 'https://': ip}
|
165
167
|
|
meutils/apis/textin.py
CHANGED
@@ -9,6 +9,8 @@
|
|
9
9
|
# @Description : todo: 重构 https://tools.textin.com/
|
10
10
|
# https://www.textin.com/console/recognition/robot_enhance?service=watermark-remove
|
11
11
|
|
12
|
+
# proxies 取消了 https://github.com/encode/httpx/pull/2879
|
13
|
+
|
12
14
|
from meutils.pipe import *
|
13
15
|
from meutils.decorators.retry import retrying
|
14
16
|
from meutils.notice.feishu import send_message
|
@@ -21,14 +23,7 @@ ua = UserAgent()
|
|
21
23
|
|
22
24
|
BASE_URL = "https://api.textin.com/home"
|
23
25
|
|
24
|
-
|
25
|
-
ip = "http://proxy.chatfire.cn/"
|
26
|
-
proxies = {
|
27
|
-
"http://": ip, # 自建 8443
|
28
|
-
"https://": ip,
|
29
|
-
}
|
30
|
-
|
31
|
-
|
26
|
+
proxy = "http://110.42.51.201:38443"
|
32
27
|
|
33
28
|
|
34
29
|
@alru_cache(ttl=3600 * 24)
|
@@ -72,27 +67,32 @@ async def document_process(data: bytes,
|
|
72
67
|
logger.debug(response.status_code)
|
73
68
|
# logger.info(response.json()) # {'msg': '今日请求超过限制次数', 'code': 431}
|
74
69
|
|
75
|
-
|
76
|
-
|
70
|
+
_ = response.json()
|
71
|
+
|
72
|
+
raise Exception("更新请求头或者加代理")
|
73
|
+
|
74
|
+
# if '今日请求超过限制次数' in str(_):
|
75
|
+
# # logger.info(response.json())
|
76
|
+
# raise Exception("更新请求头或者加代理")
|
77
|
+
# else:
|
78
|
+
# break
|
77
79
|
|
78
|
-
if '今日请求超过限制次数' in str(_):
|
79
|
-
# logger.info(response.json())
|
80
|
-
raise Exception("更新请求头或者加代理")
|
81
|
-
else:
|
82
|
-
break
|
83
80
|
|
84
81
|
except Exception as e: # 加代理
|
85
82
|
logger.error(e)
|
86
83
|
|
87
84
|
request_kwargs = {
|
88
|
-
"
|
89
|
-
|
85
|
+
# "proxy": await get_one_proxy(),
|
86
|
+
"proxy": proxy,
|
87
|
+
|
90
88
|
}
|
91
89
|
|
92
90
|
if response_format == "url" and service in {"watermark-remove", "crop_enhance_image"}:
|
93
91
|
if "data" not in _:
|
94
92
|
send_message(_, title=__name__)
|
95
93
|
|
94
|
+
# _ => {'msg': '今日请求超过限制次数', 'code': 431}
|
95
|
+
|
96
96
|
url = await to_url(_['data']['result']['image'])
|
97
97
|
_ = {"data": [{"url": url}]}
|
98
98
|
|
@@ -119,11 +119,11 @@ if __name__ == '__main__':
|
|
119
119
|
|
120
120
|
service = Purpose.watermark_remove.value
|
121
121
|
|
122
|
-
|
123
122
|
# service = "pdf_to_markdown"
|
124
123
|
|
125
124
|
service = 'bill_recognize_v2'
|
126
125
|
|
126
|
+
|
127
127
|
async def main(n=1):
|
128
128
|
for i in tqdm(range(n)):
|
129
129
|
try:
|
meutils/data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2024.12.05.
|
1
|
+
2024.12.05.17.36.18
|
meutils/decorators/retry.py
CHANGED
@@ -11,12 +11,17 @@
|
|
11
11
|
from meutils.pipe import *
|
12
12
|
from tenacity import retry, stop_after_attempt, before_sleep_log
|
13
13
|
from tenacity import wait_fixed, wait_exponential, wait_incrementing, wait_exponential_jitter # Wait strategy
|
14
|
-
from tenacity import retry_if_result,
|
14
|
+
from tenacity import retry_if_result, RetryCallState # 重试策略
|
15
|
+
from tenacity import retry_if_exception, retry_if_exception_type, retry_if_not_exception_type
|
15
16
|
|
16
17
|
# 不兼容异步
|
17
18
|
from meutils.notice.feishu import send_message
|
18
19
|
|
19
20
|
|
21
|
+
class IgnoredRetryException(Exception):
|
22
|
+
pass
|
23
|
+
|
24
|
+
|
20
25
|
def default_retry_error_callback(retry_state: RetryCallState, title: Optional[str] = None):
|
21
26
|
"""return the result of the last call attempt"""
|
22
27
|
# logger.debug(f"最后一次重试仍然失败调用的函数: {retry_state.outcome}")
|
@@ -50,7 +55,11 @@ def retrying(
|
|
50
55
|
max: int = 100000,
|
51
56
|
retry_error_callback: Optional[Callable[[RetryCallState], Any]] = None,
|
52
57
|
predicate: Callable[[Any], bool] = lambda r: False,
|
53
|
-
title: Optional[str] = None
|
58
|
+
title: Optional[str] = None,
|
59
|
+
ignored_exception_types: Optional[typing.Union[
|
60
|
+
typing.Type[BaseException],
|
61
|
+
typing.Tuple[typing.Type[BaseException], ...],
|
62
|
+
]] = None, # 该错误类型不重试
|
54
63
|
):
|
55
64
|
import logging
|
56
65
|
|
@@ -65,8 +74,9 @@ def retrying(
|
|
65
74
|
& retry_if_exception(not_in_status_codes)
|
66
75
|
)
|
67
76
|
| retry_if_result(predicate)
|
68
|
-
|
69
77
|
)
|
78
|
+
if ignored_exception_types:
|
79
|
+
retry_reasons = retry_reasons & retry_if_not_exception_type(ignored_exception_types)
|
70
80
|
|
71
81
|
_retry_decorator = retry(
|
72
82
|
reraise=True,
|
@@ -166,13 +176,12 @@ if __name__ == '__main__':
|
|
166
176
|
# # print(wait_incrementing(100, -10)(retry_state))
|
167
177
|
# print(wait_exponential(1, exp_base=2)(retry_state))
|
168
178
|
|
169
|
-
@retrying(3)
|
170
|
-
async def f():
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
179
|
+
# @retrying(3)
|
180
|
+
# async def f():
|
181
|
+
# logger.debug("retry")
|
182
|
+
# pass
|
183
|
+
# # 1 / 0
|
184
|
+
# raise Exception('xx')
|
176
185
|
|
177
186
|
# try:
|
178
187
|
# f()
|
@@ -181,17 +190,43 @@ if __name__ == '__main__':
|
|
181
190
|
# print(e)
|
182
191
|
# print(type(e))
|
183
192
|
|
184
|
-
@retrying(3)
|
185
|
-
def f():
|
186
|
-
# async def f():
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
193
|
+
# @retrying(3)
|
194
|
+
# def f():
|
195
|
+
# # async def f():
|
196
|
+
# logger.debug("retry")
|
197
|
+
# for i in range(10):
|
198
|
+
# yield ""
|
199
|
+
# if i == 8:
|
200
|
+
# raise Exception('xx')
|
192
201
|
|
202
|
+
# arun(f())
|
193
203
|
|
204
|
+
# f()
|
205
|
+
|
206
|
+
# 示例使用
|
207
|
+
class CustomError1(Exception):
|
208
|
+
pass
|
209
|
+
|
210
|
+
|
211
|
+
class CustomError2(Exception):
|
212
|
+
pass
|
213
|
+
|
214
|
+
|
215
|
+
@retrying(
|
216
|
+
max_retries=3,
|
217
|
+
ignored_exception_types=(CustomError1, IgnoredRetryException)
|
218
|
+
)
|
219
|
+
def my_function():
|
220
|
+
logger.debug(1)
|
221
|
+
# 模拟抛出异常
|
222
|
+
raise IgnoredRetryException("This is a custom error")
|
223
|
+
|
224
|
+
|
225
|
+
def main():
|
226
|
+
try:
|
227
|
+
my_function()
|
228
|
+
except Exception as e:
|
229
|
+
print(f"Operation failed after all retries: {e}")
|
194
230
|
|
195
|
-
# arun(f())
|
196
231
|
|
197
|
-
|
232
|
+
main()
|
File without changes
|
File without changes
|
{MeUtils-2024.12.5.15.58.45.dist-info → MeUtils-2024.12.5.17.36.18.dist-info}/entry_points.txt
RENAMED
File without changes
|
File without changes
|