改进内容: 1.ctaEngine.py saveSyncData中的content不是unicode字符串,和上下文不一致,而且在ubuntu上会有兼容问题 2. vtEngine.py LogEngine的单例模式无效,采用了新的单例模式

This commit is contained in:
XueShan 2017-12-15 13:32:36 +08:00
parent 1abb73c7ab
commit 1b385cfa11
2 changed files with 17 additions and 11 deletions

View File

@ -590,7 +590,7 @@ class CtaEngine(object):
self.mainEngine.dbUpdate(POSITION_DB_NAME, strategy.className,
d, flt, True)
content = '策略%s同步数据保存成功,当前持仓%s' %(strategy.name, strategy.pos)
content = u'策略%s同步数据保存成功,当前持仓%s' %(strategy.name, strategy.pos)
self.writeCtaLog(content)
#----------------------------------------------------------------------

View File

@ -535,9 +535,25 @@ class DataEngine(object):
########################################################################
class Singleton(type):
"""
单例应用方式:静态变量 __metaclass__ = Singleton
"""
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(name, bases, dict)
cls._instance = None
def __call__(cls, *args, **kw):
if cls._instance is None:
cls._instance = super(Singleton, cls).__call__(*args, **kw)
return cls._instance
class LogEngine(object):
"""日志引擎"""
# 单例模式
__metaclass__ = Singleton
# 日志级别
LEVEL_DEBUG = logging.DEBUG
LEVEL_INFO = logging.INFO
@ -545,16 +561,6 @@ class LogEngine(object):
LEVEL_ERROR = logging.ERROR
LEVEL_CRITICAL = logging.CRITICAL
# 单例对象
instance = None
#----------------------------------------------------------------------
def __new__(cls, *args, **kwargs):
"""创建对象,保证单例"""
if not cls.instance:
cls.instance = super(LogEngine, cls).__new__(cls, *args, **kwargs)
return cls.instance
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""