From b956769f9c6e68905386f8e9d7aa7e460a758631 Mon Sep 17 00:00:00 2001 From: lamter Date: Thu, 27 Apr 2017 15:48:40 +0800 Subject: [PATCH] =?UTF-8?q?=20-change=20:=20=E9=80=82=E9=85=8DPython3?= =?UTF-8?q?=E7=9A=84=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vn.trader/eventEngine.py | 2 +- vn.trader/vnrpc.py | 10 +++++++--- vn.trader/vtEngine.py | 5 +++-- vn.trader/vtServer.py | 9 +++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/vn.trader/eventEngine.py b/vn.trader/eventEngine.py index c96dd71e..d4ccef55 100644 --- a/vn.trader/eventEngine.py +++ b/vn.trader/eventEngine.py @@ -339,7 +339,7 @@ def test(): from PyQt4.QtCore import QCoreApplication def simpletest(event): - print u'处理每秒触发的计时器事件:%s' % str(datetime.now()) + print(u'处理每秒触发的计时器事件:%s' % str(datetime.now())) app = QCoreApplication(sys.argv) diff --git a/vn.trader/vnrpc.py b/vn.trader/vnrpc.py index c3a979c9..be3dc0ca 100644 --- a/vn.trader/vnrpc.py +++ b/vn.trader/vnrpc.py @@ -8,9 +8,13 @@ import zmq from msgpack import packb, unpackb from json import dumps, loads -import cPickle -pDumps = cPickle.dumps -pLoads = cPickle.loads +try: + import cPickle as pickle +except: + # 对 python3 的支持 + import pickle +pDumps = pickle.dumps +pLoads = pickle.loads # 实现Ctrl-c中断recv diff --git a/vn.trader/vtEngine.py b/vn.trader/vtEngine.py index 836d8b4f..9518bf5b 100644 --- a/vn.trader/vtEngine.py +++ b/vn.trader/vtEngine.py @@ -3,6 +3,7 @@ # import shelve from collections import OrderedDict from datetime import datetime +import traceback from pymongo import MongoClient from pymongo.errors import ConnectionFailure @@ -58,8 +59,8 @@ class MainEngine(object): self.addGateway(gatewayModule.gateway, gatewayModule.gatewayName) if gatewayModule.gatewayQryEnabled: self.gatewayDict[gatewayModule.gatewayName].setQryEnabled(True) - except Exception, e: - print e + except: + traceback.print_exc() #---------------------------------------------------------------------- def addGateway(self, gateway, gatewayName=None): diff --git a/vn.trader/vtServer.py b/vn.trader/vtServer.py index 1c137932..06cda832 100644 --- a/vn.trader/vtServer.py +++ b/vn.trader/vtServer.py @@ -1,8 +1,13 @@ # encoding: utf-8 import sys -reload(sys) -sys.setdefaultencoding('utf-8') +try: + # python2 需要设置编码 + reload(sys) + sys.setdefaultencoding('utf-8') +except: + # python3 不需要 + pass import vtGlobal import json import os