funcguard 0.1.8__tar.gz → 0.1.9__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.
Potentially problematic release.
This version of funcguard might be problematic. Click here for more details.
- {funcguard-0.1.8 → funcguard-0.1.9}/PKG-INFO +7 -7
- {funcguard-0.1.8 → funcguard-0.1.9}/README.md +6 -6
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard/__init__.py +2 -2
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard/time_utils.py +1 -1
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard/tools.py +1 -1
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard.egg-info/PKG-INFO +7 -7
- {funcguard-0.1.8 → funcguard-0.1.9}/setup.py +1 -1
- {funcguard-0.1.8 → funcguard-0.1.9}/LICENSE +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard/core.py +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard/printer.py +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard.egg-info/SOURCES.txt +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard.egg-info/dependency_links.txt +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard.egg-info/not-zip-safe +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard.egg-info/requires.txt +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/funcguard.egg-info/top_level.txt +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/setup.cfg +0 -0
- {funcguard-0.1.8 → funcguard-0.1.9}/tests/__init__.py +0 -0
|
@@ -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
|
|
@@ -181,10 +181,10 @@ for i in range(1, 101):
|
|
|
181
181
|
|
|
182
182
|
### 执行时间监控
|
|
183
183
|
|
|
184
|
-
使用`
|
|
184
|
+
使用`time_monitor`函数监控函数执行时间:
|
|
185
185
|
|
|
186
186
|
```python
|
|
187
|
-
from funcguard import
|
|
187
|
+
from funcguard import time_monitor
|
|
188
188
|
|
|
189
189
|
def some_function():
|
|
190
190
|
# 模拟一个耗时操作
|
|
@@ -193,14 +193,14 @@ def some_function():
|
|
|
193
193
|
return "操作完成"
|
|
194
194
|
|
|
195
195
|
# 模式1:总是打印执行时间
|
|
196
|
-
result =
|
|
196
|
+
result = time_monitor(
|
|
197
197
|
func=some_function,
|
|
198
198
|
print_mode=1
|
|
199
199
|
)
|
|
200
200
|
print(f"结果: {result}")
|
|
201
201
|
|
|
202
202
|
# 模式2:仅在超过阈值时打印警告
|
|
203
|
-
result =
|
|
203
|
+
result = time_monitor(
|
|
204
204
|
func=some_function,
|
|
205
205
|
warning_threshold=1.5, # 设置1.5秒的警告阈值
|
|
206
206
|
print_mode=2
|
|
@@ -208,7 +208,7 @@ result = monitor_execution_time(
|
|
|
208
208
|
print(f"结果: {result}")
|
|
209
209
|
|
|
210
210
|
# 模式0:不打印任何信息,仅返回结果和执行时间
|
|
211
|
-
result, duration =
|
|
211
|
+
result, duration = time_monitor(
|
|
212
212
|
func=some_function,
|
|
213
213
|
print_mode=0
|
|
214
214
|
)
|
|
@@ -293,7 +293,7 @@ print(f"结果: {result}, 耗时: {duration}秒")
|
|
|
293
293
|
- 否则返回None
|
|
294
294
|
- **功能**: 计算并打印任务执行时间统计信息,支持中英文双语输出
|
|
295
295
|
|
|
296
|
-
####
|
|
296
|
+
#### time_monitor(warning_threshold=None, print_mode=2, func=None, *args, **kwargs)
|
|
297
297
|
|
|
298
298
|
- **参数**:
|
|
299
299
|
- `warning_threshold`: 警告阈值(秒),如果执行耗时超过此值则打印警告,默认为None
|
|
@@ -167,10 +167,10 @@ for i in range(1, 101):
|
|
|
167
167
|
|
|
168
168
|
### 执行时间监控
|
|
169
169
|
|
|
170
|
-
使用`
|
|
170
|
+
使用`time_monitor`函数监控函数执行时间:
|
|
171
171
|
|
|
172
172
|
```python
|
|
173
|
-
from funcguard import
|
|
173
|
+
from funcguard import time_monitor
|
|
174
174
|
|
|
175
175
|
def some_function():
|
|
176
176
|
# 模拟一个耗时操作
|
|
@@ -179,14 +179,14 @@ def some_function():
|
|
|
179
179
|
return "操作完成"
|
|
180
180
|
|
|
181
181
|
# 模式1:总是打印执行时间
|
|
182
|
-
result =
|
|
182
|
+
result = time_monitor(
|
|
183
183
|
func=some_function,
|
|
184
184
|
print_mode=1
|
|
185
185
|
)
|
|
186
186
|
print(f"结果: {result}")
|
|
187
187
|
|
|
188
188
|
# 模式2:仅在超过阈值时打印警告
|
|
189
|
-
result =
|
|
189
|
+
result = time_monitor(
|
|
190
190
|
func=some_function,
|
|
191
191
|
warning_threshold=1.5, # 设置1.5秒的警告阈值
|
|
192
192
|
print_mode=2
|
|
@@ -194,7 +194,7 @@ result = monitor_execution_time(
|
|
|
194
194
|
print(f"结果: {result}")
|
|
195
195
|
|
|
196
196
|
# 模式0:不打印任何信息,仅返回结果和执行时间
|
|
197
|
-
result, duration =
|
|
197
|
+
result, duration = time_monitor(
|
|
198
198
|
func=some_function,
|
|
199
199
|
print_mode=0
|
|
200
200
|
)
|
|
@@ -279,7 +279,7 @@ print(f"结果: {result}, 耗时: {duration}秒")
|
|
|
279
279
|
- 否则返回None
|
|
280
280
|
- **功能**: 计算并打印任务执行时间统计信息,支持中英文双语输出
|
|
281
281
|
|
|
282
|
-
####
|
|
282
|
+
#### time_monitor(warning_threshold=None, print_mode=2, func=None, *args, **kwargs)
|
|
283
283
|
|
|
284
284
|
- **参数**:
|
|
285
285
|
- `warning_threshold`: 警告阈值(秒),如果执行耗时超过此值则打印警告,默认为None
|
|
@@ -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",
|
|
@@ -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
|
|
|
@@ -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
|
|
@@ -181,10 +181,10 @@ for i in range(1, 101):
|
|
|
181
181
|
|
|
182
182
|
### 执行时间监控
|
|
183
183
|
|
|
184
|
-
使用`
|
|
184
|
+
使用`time_monitor`函数监控函数执行时间:
|
|
185
185
|
|
|
186
186
|
```python
|
|
187
|
-
from funcguard import
|
|
187
|
+
from funcguard import time_monitor
|
|
188
188
|
|
|
189
189
|
def some_function():
|
|
190
190
|
# 模拟一个耗时操作
|
|
@@ -193,14 +193,14 @@ def some_function():
|
|
|
193
193
|
return "操作完成"
|
|
194
194
|
|
|
195
195
|
# 模式1:总是打印执行时间
|
|
196
|
-
result =
|
|
196
|
+
result = time_monitor(
|
|
197
197
|
func=some_function,
|
|
198
198
|
print_mode=1
|
|
199
199
|
)
|
|
200
200
|
print(f"结果: {result}")
|
|
201
201
|
|
|
202
202
|
# 模式2:仅在超过阈值时打印警告
|
|
203
|
-
result =
|
|
203
|
+
result = time_monitor(
|
|
204
204
|
func=some_function,
|
|
205
205
|
warning_threshold=1.5, # 设置1.5秒的警告阈值
|
|
206
206
|
print_mode=2
|
|
@@ -208,7 +208,7 @@ result = monitor_execution_time(
|
|
|
208
208
|
print(f"结果: {result}")
|
|
209
209
|
|
|
210
210
|
# 模式0:不打印任何信息,仅返回结果和执行时间
|
|
211
|
-
result, duration =
|
|
211
|
+
result, duration = time_monitor(
|
|
212
212
|
func=some_function,
|
|
213
213
|
print_mode=0
|
|
214
214
|
)
|
|
@@ -293,7 +293,7 @@ print(f"结果: {result}, 耗时: {duration}秒")
|
|
|
293
293
|
- 否则返回None
|
|
294
294
|
- **功能**: 计算并打印任务执行时间统计信息,支持中英文双语输出
|
|
295
295
|
|
|
296
|
-
####
|
|
296
|
+
#### time_monitor(warning_threshold=None, print_mode=2, func=None, *args, **kwargs)
|
|
297
297
|
|
|
298
298
|
- **参数**:
|
|
299
299
|
- `warning_threshold`: 警告阈值(秒),如果执行耗时超过此值则打印警告,默认为None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|