加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
mysave.py 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
Xvar 提交于 2021-11-27 18:18 . save init
import pymongo
import math
class CSaveManager(object):
def __init__(self):
self.m_SaveList = []
def OnSaveLoop(self):
if not self.m_SaveList:
return
iSaveCnt = math.ceil(len(self.m_SaveList)/300)
lstSave = self.m_SaveList[:iSaveCnt]
self.m_SaveList = self.m_SaveList[iSaveCnt:]
for oSaveObj in lstSave:
oSaveObj.OnSave()
class CSaveObj(object):
m_ColName = ""
def __init__(self, iID):
self.m_ID = iID
def Save(self):
data = {}
data["ID"] = self.m_ID
return data
def Load(self, data):
pass
def OnSave(self):
pass
class CMongosClient(object):
def __init__(self):
self.m_SaveList = []
oClient = pymongo.MongoClient("mongodb://localhost:27017/")
self.m_MyDB = oClient["testdb0"]
def AddSaveData(self, sCol, data):
self.m_SaveList.append((sCol, data))
def SaveLoop(self):
while True:
if self.m_SaveList:
sCol, data = self.m_SaveList.pop(0)
self.m_MyDB[sCol].update_one(data)
def Init():
global g_SaveManager
g_SaveManager = CSaveManager()
def GetSaveManager():
global g_SaveManager
return g_SaveManager
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化