class DataBase:
"""
"""
def __init__(self, setting: Dict = None):
"""
"""
self.process_count = 0
@staticmethod
def counter_decorator(func: Callable) -> Callable:
"""装饰函数运行达到一定次数后提交"""
@functools.wraps(func)
def wrapper(self, *args, **kwargs):
self.process_count += 1
result = func(self, *args, **kwargs)
if self.process_count % 50 == 0:
self.session.flush()
self.session.commit()
return result
return wrapper
@counter_decorator
def save_data(self, ormobj):
self.session.merge(ormobj)
标签:process,self,session,类中,func,方法,装饰,def
From: https://www.cnblogs.com/meizhengchao/p/18215789