pip install geeker
觉得好用请点个star,分享给更多的人使用
from geeker import schedule
import time
def abc():
print('abc')
# 注册任务
schedule.every(2).seconds.do(abc)
schedule.every().day.at("10:00").do(abc)
# 开启任务
while True:
# thread_pool=False(默认)不会使用线程池,如果上个任务耗时很长,
# 在下一次任务启动时间点仍未完成,会造成下次任务延后
schedule.run_pending()
# 参数max_worker 控制任务的总数,默认是任务数的2倍.
# 注意,如果设置一个较大值,请考虑内存是否允许
# schedule.run_pending(thread_pool=True, max_worker=5)
time.sleep(1)
:param dir_path: 日志记录的路径,默认是当前路径下的log文件夹
:param logger_name: logger对象的名字
:param info_name: 保存info等级的文件名字
:param error_name:
:param warning_name:
:param debug_name:
:param interval: 压缩日志的频率,默认是7天
:param detail: bool值,记录日志是否为详细记录
:param debug: 是否记录debug,默认不记录
:param info: 是否记录info,默认记录
:param error:
:param warning:
# 实例方法:
get_logger()-->logger
from geeker import MyLog
# 记录四种类型的日志
logger = MyLog(debug=True).get_logger()
logger.info('info')
logger.debug('debug')
logger.error('error')
logger.warning('warning')
# # # # # # # # # # # # # # # # # # # # # # # # #
# 只记录错误日志
logger = MyLog(info=False,warning=False).get_logger()
logger.info('info')
logger.debug('debug')
logger.error('error')
logger.warning('warning')
mylog = MyLog('./logs/logs/')
mylog2 = MyLog()
logger = mylog.get_logger()
logger2 = mylog2.get_logger()
logger.info('info')
logger2 = MyLog('./logs/logs2/').get_logger()
logger2.info('info2')
(仅用于多线程模型,协程无效)
from geeker import Concurrency
# 每4秒执行5次abc()
@Concurrency(5,4)
def abc():
pass
# 并发量为5
@Concurrency(5)
def abc():
pass
class Test:
def __init__(self):
pass
@Concurrency(3)
def test(self, a):
print(a, self)
time.sleep(a)
from geeker import runtime
@run_time
def test(i):
# int('asfa')
time.sleep(i)
print('运行结果:', i)
>>>
START test(1, {})
运行结果: 1
test(1, {}) takes <1.0006> seconds
STOP test(1, {})
from geeker import Singleton
# 实例的属性为第一次初始化时的属性
class Test(Singleton):
pass
from geeker import SingletonOverride
# 后面创建的实例属性会覆盖前者的实例属性
class Test(SingletonOverride):
pass
from geeker import TimeOut
# 精度为0.1秒
@TimeOut(4)
def test(i):
time.sleep(i)
class AA:
@TimeOut(3.0)
def test(self, i):
time.sleep(i)
from geeker import MyType
class Test:
lll = MyType('str_type1', expect_type=str)
llll = MyType('str_type2', expect_type=str)
def __init__(self, value, ):
self.lll = value
self.llll = value
from geeker import MyDict
a=MyDict()
a.append_key('key','value')
a.o=5
a.c='fasf'
a.add_key('key0','value0')
print(dict(a))
使用dict()函数可以直接转换为字典格式
>>>{
'key': ['value'],
'o': 5,
'c': 'fasf',
'key0': {'value0'}
}
from geeker import IdGenerator
id_generator =IdGenerator()
_id =id_generator.get_id()
from geeker import show_memory_info
show_memory_info()
from geeker import retry
@retry(5, ValueError)
def test():
int('asf')