修改为在设置的gateway清单中进行加载,减少轮询目录的耗时。

This commit is contained in:
msincenselee 2017-05-11 18:58:35 +08:00
parent 4cc6497560
commit e907dacaa1

View File

@ -11,9 +11,26 @@ import traceback
# 用来保存Gateway类的字典 # 用来保存Gateway类的字典
GATEWAY_DICT = {} GATEWAY_DICT = {}
# modified by Incense Lee
# 只加载指定的gateway清单
# 需要加载的gateway清单 # 需要加载的gateway清单
load_gateways = ['ctpGateway'] load_gateways = ['ctpGateway']
# 逐一加载
for load_gateway in load_gateways:
# 模块名称需要上前缀
moduleName = 'gateway.' + load_gateway
print u'load Module:{0}'.format(moduleName)
try:
# 使用importlib动态载入模块并保存到字典中
module = importlib.import_module(moduleName)
GATEWAY_DICT[module.gatewayName] = module
except Exception as ex:
print u'Load {0} exception:{1}'.format(moduleName, ex)
traceback.print_exc()
"""
# 获取目录路径 # 获取目录路径
path = os.path.abspath(os.path.dirname(__file__)) path = os.path.abspath(os.path.dirname(__file__))
@ -41,3 +58,4 @@ for root, subdirs, files in os.walk(path):
print u'Load {0} exception:{1}'.format(moduleName, ex) print u'Load {0} exception:{1}'.format(moduleName, ex)
traceback.print_exc() traceback.print_exc()
"""