Skip to content

Commit

Permalink
2024年7月15日 添加执行时间装饰器
Browse files Browse the repository at this point in the history
  • Loading branch information
ss1917 committed Jul 15, 2024
1 parent 2bd3e23 commit 5497eba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
28 changes: 23 additions & 5 deletions websdk2/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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


### 令牌桶限流
'''
示例
Expand Down

0 comments on commit 5497eba

Please sign in to comment.