diff --git a/setup.py b/setup.py index 13f0c89..10c8238 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ import sys from distutils.core import setup -VERSION = '1.0.5' +VERSION = '1.0.6' if sys.version_info < (2, 7) or (3, 0) <= sys.version_info < (3, 6): print('This program requires at least Python 2.7 or 3.6 to run.') diff --git a/websdk2/utils/__init__.py b/websdk2/utils/__init__.py index 0916a52..22c61f8 100644 --- a/websdk2/utils/__init__.py +++ b/websdk2/utils/__init__.py @@ -7,16 +7,17 @@ Desc : """ +import json import os +import smtplib +import socket import time -import json import uuid -import socket -import smtplib from datetime import datetime -from ..consts import const -from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + +from ..consts import const class SendMail(object): @@ -197,6 +198,23 @@ def echo_datetime_now_f(): return datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') +def echo_execute_time(func): + import logging + from time import time + + # 定义嵌套函数,用来打印出装饰的函数的执行时间 + def wrapper(*args, **kwargs): + # 定义开始时间和结束时间,将func夹在中间执行,取得其返回值 + start = time() + func_return = func(*args, **kwargs) + end = time() + logging.warning(f'{func.__name__}() execute time: {end - start}s') + return func_return + + # 返回嵌套的函数 + return wrapper + + ### 令牌桶限流 ''' 示例