From 0a0a9cda1af4a7093c0ccc9ba9d0486e6f37938d Mon Sep 17 00:00:00 2001 From: qzbysh Date: Wed, 18 May 2016 21:15:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMongoDB=E8=BF=9E=E6=8E=A5bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复在MongoDB服务端异常情况下,启动vnpy依然显示MongoDB连接成功bug。 修改‘serverSelectionTimeoutMS’为3s(默认30s), 利用server_info()函数测试服务器是否正常。 --- vn.trader/vtEngine.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vn.trader/vtEngine.py b/vn.trader/vtEngine.py index 45b7e709..70d24eda 100644 --- a/vn.trader/vtEngine.py +++ b/vn.trader/vtEngine.py @@ -208,7 +208,8 @@ class MainEngine(object): host, port = loadMongoSetting() try: - self.dbClient = MongoClient(host, port) + self.dbClient = MongoClient(host, port, serverSelectionTimeoutMS=3000) + self.dbClient.server_info() self.writeLog(u'MongoDB连接成功') except ConnectionFailure: self.writeLog(u'MongoDB连接失败') @@ -349,4 +350,4 @@ class DataEngine(object): self.eventEngine.register(EVENT_ORDER, self.updateOrder) - \ No newline at end of file +