funcguard 0.1.8__py3-none-any.whl → 0.1.9__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.
Potentially problematic release.
This version of funcguard might be problematic. Click here for more details.
- funcguard/__init__.py +2 -2
- funcguard/time_utils.py +1 -1
- funcguard/tools.py +1 -1
- {funcguard-0.1.8.dist-info → funcguard-0.1.9.dist-info}/METADATA +7 -7
- funcguard-0.1.9.dist-info/RECORD +11 -0
- funcguard-0.1.8.dist-info/RECORD +0 -11
- {funcguard-0.1.8.dist-info → funcguard-0.1.9.dist-info}/LICENSE +0 -0
- {funcguard-0.1.8.dist-info → funcguard-0.1.9.dist-info}/WHEEL +0 -0
- {funcguard-0.1.8.dist-info → funcguard-0.1.9.dist-info}/top_level.txt +0 -0
funcguard/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from .core import timeout_handler, retry_function
|
|
2
2
|
from .tools import send_request
|
|
3
|
-
from .time_utils import time_log, time_diff,
|
|
3
|
+
from .time_utils import time_log, time_diff, time_monitor
|
|
4
4
|
from .printer import print_block, print_line, print_title
|
|
5
5
|
|
|
6
6
|
__author__ = "ruocen"
|
|
@@ -12,7 +12,7 @@ __all__ = [
|
|
|
12
12
|
"send_request",
|
|
13
13
|
"time_log",
|
|
14
14
|
"time_diff",
|
|
15
|
-
"
|
|
15
|
+
"time_monitor",
|
|
16
16
|
"print_block",
|
|
17
17
|
"print_line",
|
|
18
18
|
"print_title",
|
funcguard/time_utils.py
CHANGED
|
@@ -97,7 +97,7 @@ def time_diff(s_time = None, max_num = 0, language = "cn", return_duration = 1)
|
|
|
97
97
|
|
|
98
98
|
|
|
99
99
|
# 监控程序的执行时间
|
|
100
|
-
def
|
|
100
|
+
def time_monitor(warning_threshold=None, print_mode=2, func=None, *args, **kwargs):
|
|
101
101
|
"""
|
|
102
102
|
监控函数执行时间,并返回函数的执行结果和执行时间
|
|
103
103
|
|
funcguard/tools.py
CHANGED
|
@@ -3,7 +3,7 @@ import requests
|
|
|
3
3
|
from datetime import datetime, timezone, timedelta
|
|
4
4
|
from typing import Optional, Dict, Any, Union
|
|
5
5
|
from .core import retry_function
|
|
6
|
-
from .time_utils import time_log, time_diff,
|
|
6
|
+
from .time_utils import time_log, time_diff, time_monitor
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
# 发起请求
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: funcguard
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.9
|
|
4
4
|
Summary: FuncGuard是一个Python库,提供函数执行超时控制、重试机制、HTTP请求封装和格式化打印工具。
|
|
5
5
|
Home-page: https://github.com/tinycen/funcguard
|
|
6
6
|
Author: tinycen
|
|
@@ -182,10 +182,10 @@ for i in range(1, 101):
|
|
|
182
182
|
|
|
183
183
|
### 执行时间监控
|
|
184
184
|
|
|
185
|
-
使用`
|
|
185
|
+
使用`time_monitor`函数监控函数执行时间:
|
|
186
186
|
|
|
187
187
|
```python
|
|
188
|
-
from funcguard import
|
|
188
|
+
from funcguard import time_monitor
|
|
189
189
|
|
|
190
190
|
def some_function():
|
|
191
191
|
# 模拟一个耗时操作
|
|
@@ -194,14 +194,14 @@ def some_function():
|
|
|
194
194
|
return "操作完成"
|
|
195
195
|
|
|
196
196
|
# 模式1:总是打印执行时间
|
|
197
|
-
result =
|
|
197
|
+
result = time_monitor(
|
|
198
198
|
func=some_function,
|
|
199
199
|
print_mode=1
|
|
200
200
|
)
|
|
201
201
|
print(f"结果: {result}")
|
|
202
202
|
|
|
203
203
|
# 模式2:仅在超过阈值时打印警告
|
|
204
|
-
result =
|
|
204
|
+
result = time_monitor(
|
|
205
205
|
func=some_function,
|
|
206
206
|
warning_threshold=1.5, # 设置1.5秒的警告阈值
|
|
207
207
|
print_mode=2
|
|
@@ -209,7 +209,7 @@ result = monitor_execution_time(
|
|
|
209
209
|
print(f"结果: {result}")
|
|
210
210
|
|
|
211
211
|
# 模式0:不打印任何信息,仅返回结果和执行时间
|
|
212
|
-
result, duration =
|
|
212
|
+
result, duration = time_monitor(
|
|
213
213
|
func=some_function,
|
|
214
214
|
print_mode=0
|
|
215
215
|
)
|
|
@@ -294,7 +294,7 @@ print(f"结果: {result}, 耗时: {duration}秒")
|
|
|
294
294
|
- 否则返回None
|
|
295
295
|
- **功能**: 计算并打印任务执行时间统计信息,支持中英文双语输出
|
|
296
296
|
|
|
297
|
-
####
|
|
297
|
+
#### time_monitor(warning_threshold=None, print_mode=2, func=None, *args, **kwargs)
|
|
298
298
|
|
|
299
299
|
- **参数**:
|
|
300
300
|
- `warning_threshold`: 警告阈值(秒),如果执行耗时超过此值则打印警告,默认为None
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
funcguard/__init__.py,sha256=Tr5d54OPz1tK9nBQKjiYlSKAR0nmqsU4HpRrkRoRS3k,431
|
|
2
|
+
funcguard/core.py,sha256=-rFRkE-udxM0wxlcv9Qi_yIQBRdVrGgwza-LYQsVRLg,3632
|
|
3
|
+
funcguard/printer.py,sha256=Iig_UO4h5LcL0BqCEEdxiu32h4rUq9GJbmf1pC_hd7o,1462
|
|
4
|
+
funcguard/time_utils.py,sha256=AZ3rPJkepnFL3Z66h0miql8-Elox0knn7q1RbqMrpsc,6129
|
|
5
|
+
funcguard/tools.py,sha256=zocd9rMP8fzEPLoU4yfRrTKcX57qF10fFYk38lyhif8,2081
|
|
6
|
+
tests/__init__.py,sha256=VW6FdWdSC_PL3zEtpkRQfUMf6yVD2OfwtSds82jawTs,26
|
|
7
|
+
funcguard-0.1.9.dist-info/LICENSE,sha256=jgOquECfjiXp5xXQ2zuzItDr4XDBLan-bIzIXl1lS4Y,1064
|
|
8
|
+
funcguard-0.1.9.dist-info/METADATA,sha256=YpiwpYYF3e2qBz9MffaN8WavVdH2Y_lpcbeNNt8uQ5M,10598
|
|
9
|
+
funcguard-0.1.9.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
10
|
+
funcguard-0.1.9.dist-info/top_level.txt,sha256=7wL9mWT062DttKNO7Wi1wYWTZilR2AOPRO0rE3gvtB4,16
|
|
11
|
+
funcguard-0.1.9.dist-info/RECORD,,
|
funcguard-0.1.8.dist-info/RECORD
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
funcguard/__init__.py,sha256=irZLaE4wDu4bRilk0ySHy7ZTZD0-CGWaogrC7MCKM3k,451
|
|
2
|
-
funcguard/core.py,sha256=-rFRkE-udxM0wxlcv9Qi_yIQBRdVrGgwza-LYQsVRLg,3632
|
|
3
|
-
funcguard/printer.py,sha256=Iig_UO4h5LcL0BqCEEdxiu32h4rUq9GJbmf1pC_hd7o,1462
|
|
4
|
-
funcguard/time_utils.py,sha256=be7l6vMivWAfmLP4V91z9jRUYfnn-T4XrCU21eQkXeo,6139
|
|
5
|
-
funcguard/tools.py,sha256=J25wE1JCRqfDnJn7NJGaS9nepATPxNJT4ko4ITkghQA,2091
|
|
6
|
-
tests/__init__.py,sha256=VW6FdWdSC_PL3zEtpkRQfUMf6yVD2OfwtSds82jawTs,26
|
|
7
|
-
funcguard-0.1.8.dist-info/LICENSE,sha256=jgOquECfjiXp5xXQ2zuzItDr4XDBLan-bIzIXl1lS4Y,1064
|
|
8
|
-
funcguard-0.1.8.dist-info/METADATA,sha256=l7J2kuqmcjPUPnyCDt10leuNvwGJpLrSiMSM3sbxzZc,10658
|
|
9
|
-
funcguard-0.1.8.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
10
|
-
funcguard-0.1.8.dist-info/top_level.txt,sha256=7wL9mWT062DttKNO7Wi1wYWTZilR2AOPRO0rE3gvtB4,16
|
|
11
|
-
funcguard-0.1.8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|