From d9b91ccb690a6da2605425ec045e657c2c16b26c Mon Sep 17 00:00:00 2001 From: chenxy123 Date: Thu, 19 May 2016 23:33:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9MongoDB=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E8=B6=85=E6=97=B6=E7=9A=84=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/vtEngine.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vn.trader/vtEngine.py b/vn.trader/vtEngine.py index 70d24eda..4f9fe850 100644 --- a/vn.trader/vtEngine.py +++ b/vn.trader/vtEngine.py @@ -208,8 +208,12 @@ class MainEngine(object): host, port = loadMongoSetting() try: - self.dbClient = MongoClient(host, port, serverSelectionTimeoutMS=3000) + # 设置MongoDB操作的超时时间为0.5秒 + self.dbClient = MongoClient(host, port, serverSelectionTimeoutMS=500) + + # 调用server_info查询服务器状态,防止服务器异常并未连接成功 self.dbClient.server_info() + self.writeLog(u'MongoDB连接成功') except ConnectionFailure: self.writeLog(u'MongoDB连接失败')