decorator tool collection
Project description
常用装饰器工具集
pip安装
pip install detool
1.统计函数执行时长装饰器
import time
from detool import timer_cost
@timer_cost
def t_time():
time.sleep(0.01)
print(123)
2.redis缓存装饰器
from detool import RedisCache
redis_cache = RedisCache(host='127.0.0.1', password='', port=6379, db=0)
@redis_cache.cache(ttl=30)
def sum_t(a, b):
print(f'{a}+{b}={a + b}')
return a + b
r = sum_t(1, 2)
print(r)
3.日志装饰器
from detool import class_log_decorator,log_decorator
@class_log_decorator
class Cal(object):
def __init__(self, c):
self.c = c
def sum(self, a, b):
return a + b
@log_decorator
def calculate(a, b):
return a + b
Cal(3).sum(a=3, b=6)
4.异常捕获装饰器
from detool import class_exception_decorator,exception_decorator
@exception_decorator
def r_exception():
raise Exception("function Exception raised")
@class_exception_decorator
class ClassException(object):
def r_exception(self):
raise Exception("class Exception raised")
r_exception()
ClassException().r_exception()
5.分析内存装饰器
from detool import profile
@profile
def t_memory():
return [i for i in range(1, 1001)]
t_memory()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
detool-1.1.3.tar.gz
(4.0 kB
view details)
Built Distribution
File details
Details for the file detool-1.1.3.tar.gz
.
File metadata
- Download URL: detool-1.1.3.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.4.2 requests/2.24.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8702aa10982ef2c3465d4b5f26e552c7bc4f9e4fb1cff4ec5caf90bbd3b358c9 |
|
MD5 | 41e053a9bbbd535b526ca1ab6ff2e21c |
|
BLAKE2b-256 | 15ce47b230634ee3dc66f8de875ed155b0ff40d7e51c2ff24eebf3ba14662cf0 |
File details
Details for the file detool-1.1.3-py3-none-any.whl
.
File metadata
- Download URL: detool-1.1.3-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.4.2 requests/2.24.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 93c0e28ed549e82adc03891fed7a58b2a48500b442c47f9071439747ad58a87d |
|
MD5 | e1b81632893ab7eaf12b92cd1f8274c3 |
|
BLAKE2b-256 | 89c604342b09fea0c62214046a556403eeaf679a73889fcb755e68599739972b |