本文整理汇总了Python中sgLib.core.Gcore.getNewDB方法的典型用法代码示例。如果您正苦于以下问题:Python Gcore.getNewDB方法的具体用法?Python Gcore.getNewDB怎么用?Python Gcore.getNewDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sgLib.core.Gcore
的用法示例。
在下文中一共展示了Gcore.getNewDB方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: loop
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
def loop(self):
print 'Rabbit.loop()'
delay = 1 #延迟标志 1数据库内有延迟 0没有
while True:
msg = self._queue.get()
try:
self.send(msg)
if delay:
db = Gcore.getNewDB()
rows = db.out_rows('tb_delay_mq','*')
if rows:
for row in rows:
print 'tb_delay_mq',row
affected_row = db.update('tb_delay_mq', {'lockstate':1}, "id=%s AND lockstate=0"%row['id'])
if affected_row:
try:
msgdelay = eval(row['msg']) #需要把这条消息发出去
except Exception:
continue
else:
self.send(msgdelay)
finally:
db.delete('tb_delay_mq','id=%s'%row['id'])
db.close()
delay = 0
except Exception, e:
print 'Exception at Rabbit.loop() ',e
#将队列插入数据库
db = Gcore.getNewDB()
dic = {
'msg':str(msg),
'CreateTime':Gcore.common.nowtime(),
}
result = db.insert('tb_delay_mq',dic)
if not result:
self._queue.put(msg) #如果插不进去 再加回队列中
gevent.sleep(10) #等待数据库恢复
db.close()
delay = 1
self.con = None
示例2: __init__
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
def __init__(self):
self.db = Gcore.getNewDB()
self.mapInfo = {
1:'becomehold',
2:'freehold',
3:'autofree',
4:'befight',
5:'defenseDamage',
6:'battleReport',
7:'lostCoin',
8:'gainHonour',
9:'gotProtect',
}
示例3: loop
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
def loop(self):
"""用协程一直查有没有队列信息要发"""
delay = 1 # 延迟标志 1数据库内有延迟 0没有
print "MyRedis.loop()"
while True:
buff = self._queue.get()
dic = json.loads(buff)
try:
if delay:
db = Gcore.getNewDB()
# 将数据库记录查出来再set,如果set成功就删除记录
try:
rows = db.out_rows("tb_delay_redis", "*")
if rows:
for row in rows:
affected_row = db.update(
"tb_delay_redis", {"lockstate": 1}, "id=%s AND lockstate=0" % row["id"]
)
if affected_row:
try:
# print 'affected_row',affected_row
# callMethod = getattr(Redis,row['method'])
if row["method"] == "hset":
Redis.hset(self, row["h"], row["k"], row["v"])
if not Gcore.IsServer:
print "delay Redis.hset", row["h"], row["k"], row["v"]
elif row["method"] == "set":
Redis.set(self, row["k"], row["v"])
if not Gcore.IsServer:
print "delay Redis.set", row["k"], row["v"]
db.delete("tb_delay_redis", "id=%s" % row["id"]) # 删除
except:
db.update("tb_delay_redis", {"lockstate": 0}, "id=%s" % row["id"]) # 解锁
except Exception, e:
print e
pass
finally:
db.close()
if dic["method"] == "hset":
Redis.hset(self, dic["h"], dic["k"], dic["v"])
elif dic["method"] == "set":
Redis.set(self, dic["k"], dic["v"])
# print 'Redis.set',dic['k'],dic['v']
delay = 0
示例4: _test
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
def _test():
'''模块内测试'''
r = RedisMod(1032)
print r.OnCacheFriends()
db = Gcore.getNewDB()
for UserId in db.out_list('tb_user', 'UserId',"UserId=1001 or 1" ): # OR 1
print db.sql
c = RedisMod(UserId)
#print c.offCacheAll() #下线
#print c.onCacheAll() #上线
#print c.offCacheWallDefense()
#c.offCacheGeneral()
#c = RedisMod(UserId,2)
#c.offCacheWallDefense()
#c.cacheUserInfo()
#c.offCacheGeneral()
Gcore.runtime()
import time
time.sleep(5)
示例5: str
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
for row in rows:
if row["HoldEndTime"] > curtime:
continue
if row["HolderServerId"] == config.SERVER_ID: #本服
ui = Gcore.getUI('Building_hold', row["HolderId"])
ui.SlaveOperand({'typ':2, 'uid':row["UserId"], 'sid':config.SERVER_ID})
else: #非本服,发消息
try:
msg = {'HolderId':row["HolderId"], "GiverId":row["UserId"], "GiverServerId":config.SERVER_ID}
msg['optId'] = 3
msg = str(msg)
message = amqp.Message(msg)
message.properties['delivery_mod'] = 2
s2e = int(row["HolderServerId"])%exchange_num
if not s2e:
s2e = exchange_num
chan = ensure_conn(send_conn)
chan.basic_publish(message, exchange='sggameexchange%d'%s2e, routing_key=str(row["HolderServerId"]))
except Exception:
#将队列插入数据库 @todo待测试
db = Gcore.getNewDB()
dic = {
'msg':msg,
'CreateTime':Gcore.common.nowtime(),
}
result = db.insert('tb_delay_mq',dic)
db.close()
cnt += 1
示例6: __init__
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
def __init__(self):
self.db = Gcore.getNewDB()
self.fd = None #将修改过的数据写入文件,备份,防止出错
示例7: __init__
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
def __init__(self):
self.db = Gcore.getNewDB()
示例8: __init__
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
def __init__(self):
self.db = Gcore.getNewDB()
self.mailConId2Goods = {}
示例9: checkOpt
# 需要导入模块: from sgLib.core import Gcore [as 别名]
# 或者: from sgLib.core.Gcore import getNewDB [as 别名]
def checkOpt(uid,optId,para):
'''将协议号定位于功能'''
#global runtime_logger
#global exception_logger
print ' --> ps proManager.checkOpt',uid,optId
if optId not in proManager.mappingDict:
return Gcore.error(optId,-11111111) #协议号未定义,或程序未更新
try:
startTime = time.time()
mapInfo = proManager.mappingDict.get(optId)
calledMethod = getattr(Gcore.getUI(mapInfo[0],uid),mapInfo[1])
response = calledMethod(para)
#if Gcore.TEST and Gcore.IsServer: #调试计时
if True and optId not in [91005,99001,99002,99003,99004,99005,99006]: #扫荡不计 因为一次gevent.sleep(3.5)
try:
runtime = time.time() - startTime
#print '-------before log runtime---------'
db = Gcore.getNewDB()
row = {
'UserId':uid,
'OptId':optId,
'CallMethod':'%s.%s'%(mapInfo[0],mapInfo[1]),
'Param':Gcore.common.json_encode(para),
'Response':Gcore.common.json_encode(response),
'Runtime':runtime,
'RecordTime':Gcore.common.datetime(),
}
db.insert('temp_runtime_log', row, isdelay=True)
db.close()
#print '-------end log runtime---------'
#runtime_logger.info("%s\t%s\t%s\t%s\t%s\t%s\t%s" % map(str, [uid, optId, str((mapInfo[0],mapInfo[1])),
# Gcore.common.json_encode(para),
# Gcore.common.json_encode(response),
# runtime,
# Gcore.common.datetime()]))
except:
pass
return response
except Exception,e:
print '==Exception==',e
mapInfo = proManager.mappingDict.get(optId)
#if Gcore.TEST and Gcore.IsServer:
if Gcore.IsServer:
import traceback
strExcept = traceback.format_exc()
print >>sys.stderr, 'Time:' + time.strftime('%Y-%m-%d %H:%M:%S') + '\n' \
+ 'UserId:' + str(uid) + '\n' \
+ 'OptId:' + str(optId) + '\n' \
+ 'Para:' + str(para) + '\n' \
+ strExcept
sys.stderr.flush()
#strExcept = str(mapInfo[0])+'.'+str(mapInfo[1])+' >> '+str(e)+'\n'
#strExcept = strExcept+('\n'.join(traceback.format_exc().splitlines()[-3:]))#最后三行traceback
body = {'Exception':strExcept}
#print '-------before log excetion---------'
db = Gcore.getNewDB()
# row = {
# 'UserId':uid,
# 'OptId':optId,
# 'CallMethod':'%s.%s'%(mapInfo[0],mapInfo[1]),
# 'Param':Gcore.common.json_encode(para),
# 'Exception':strExcept,
# 'RecordTime':Gcore.common.datetime(),
# }
# db.insert('temp_exception_log', row, isdelay=True)
# print 'db.sql',db.sql
#OptId,Exception 为唯一
RecordTime = Gcore.common.datetime()
CallMethod = '%s.%s'%(mapInfo[0],mapInfo[1])
Param = Gcore.common.json_encode(para)
strExcept = db.escape_string(strExcept)
sql = "INSERT INTO temp_exception_log (OptId,Exception,RecordTime,CallMethod,UserId,Param)"
sql += " VALUES ('%s','%s','%s','%s','%s','%s') ON DUPLICATE KEY UPDATE UserId='%s',ApearTimes=ApearTimes+1,RecordTime='%s'" \
%(optId,strExcept,RecordTime,CallMethod,uid,Param,uid,RecordTime)
db.execute(sql,None,True)
#print '-------end log excetion---------'
#exception_logger.exception("%s\t%s\t%s\t%s\t%s\%s\t%s\t%s" % map(str, [optId,strExcept,RecordTime,CallMethod,uid,Param,uid,RecordTime]))
else:
body = {}
# if Gcore.TEST or True:
# time.sleep(1)
# raise
return Gcore.error(optId,-22222222,body) #程序运行错误