Skip to content

Commit 5497eba

Browse files
committed
2024年7月15日 添加执行时间装饰器
1 parent 2bd3e23 commit 5497eba

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import sys
1010
from distutils.core import setup
1111

12-
VERSION = '1.0.5'
12+
VERSION = '1.0.6'
1313

1414
if sys.version_info < (2, 7) or (3, 0) <= sys.version_info < (3, 6):
1515
print('This program requires at least Python 2.7 or 3.6 to run.')

websdk2/utils/__init__.py

+23-5
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
Desc :
88
"""
99

10+
import json
1011
import os
12+
import smtplib
13+
import socket
1114
import time
12-
import json
1315
import uuid
14-
import socket
15-
import smtplib
1616
from datetime import datetime
17-
from ..consts import const
18-
from email.mime.text import MIMEText
1917
from email.mime.multipart import MIMEMultipart
18+
from email.mime.text import MIMEText
19+
20+
from ..consts import const
2021

2122

2223
class SendMail(object):
@@ -197,6 +198,23 @@ def echo_datetime_now_f():
197198
return datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
198199

199200

201+
def echo_execute_time(func):
202+
import logging
203+
from time import time
204+
205+
# 定义嵌套函数,用来打印出装饰的函数的执行时间
206+
def wrapper(*args, **kwargs):
207+
# 定义开始时间和结束时间,将func夹在中间执行,取得其返回值
208+
start = time()
209+
func_return = func(*args, **kwargs)
210+
end = time()
211+
logging.warning(f'{func.__name__}() execute time: {end - start}s')
212+
return func_return
213+
214+
# 返回嵌套的函数
215+
return wrapper
216+
217+
200218
### 令牌桶限流
201219
'''
202220
示例

0 commit comments

Comments
 (0)