From 34bce32dc0f7ffc4ea56348d9c615ee4ba43969a Mon Sep 17 00:00:00 2001 From: nanoric Date: Fri, 8 Mar 2019 07:40:54 -0400 Subject: [PATCH] =?UTF-8?q?[Fix]=20=E4=BF=AE=E5=A4=8Dstop()=E4=B9=8B?= =?UTF-8?q?=E5=90=8E=E8=BF=98=E9=87=8D=E8=BF=9E=E4=B8=80=E6=AC=A1=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/gateway/oes/oes_md.py | 21 +++++++++++---------- vnpy/gateway/oes/oes_td.py | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/vnpy/gateway/oes/oes_md.py b/vnpy/gateway/oes/oes_md.py index 1d45e56f..476799df 100644 --- a/vnpy/gateway/oes/oes_md.py +++ b/vnpy/gateway/oes/oes_md.py @@ -31,9 +31,10 @@ class OesMdMessageLoop: """""" self.gateway = gateway self.env = env - self.alive = False - self.md = md - self.th = Thread(target=self._message_loop) + + self._alive = False + self._md = md + self._th = Thread(target=self._message_loop) self.message_handlers: Dict[int, Callable[[dict], None]] = { # tick & orderbook @@ -64,21 +65,21 @@ class OesMdMessageLoop: def start(self): """""" - self.alive = True - self.th.start() + self._alive = True + self._th.start() def stop(self): """""" - self.alive = False + self._alive = False def join(self): """""" - self.th.join() + self._th.join() def reconnect(self): """""" self.gateway.write_log(_("正在尝试重新连接到行情服务器。")) - return self.md.connect() + return self._md.connect() def _get_last_tick(self, symbol): """""" @@ -117,7 +118,7 @@ class OesMdMessageLoop: timeout_ms = 1000 # is_timeout = SPlatform_IsNegEtimeout is_disconnected = SPlatform_IsNegEpipe - while self.alive: + while self._alive: ret = MdsApi_WaitOnMsg(tcp_channel, timeout_ms, self._on_message) @@ -126,7 +127,7 @@ class OesMdMessageLoop: # pass # just no message if is_disconnected(ret): self.gateway.write_log(_("与行情服务器的连接已断开。")) - while not self.reconnect() and self.alive: + while self._alive and not self.reconnect(): time.sleep(1) return diff --git a/vnpy/gateway/oes/oes_td.py b/vnpy/gateway/oes/oes_td.py index 77184c32..f0f8f9a1 100644 --- a/vnpy/gateway/oes/oes_td.py +++ b/vnpy/gateway/oes/oes_td.py @@ -186,7 +186,7 @@ class OesTdMessageLoop: # pass # just no message if is_disconnected(ret): self.gateway.write_log(_("与交易服务器的连接已断开。")) - while not self.reconnect() and self._alive: + while self._alive and not self.reconnect(): pass return