From 0ee13bf862c747566e4721bd8237305c9ae01947 Mon Sep 17 00:00:00 2001 From: nanoric Date: Thu, 11 Oct 2018 22:05:43 -0400 Subject: [PATCH] =?UTF-8?q?[Add]=20RestClient:=E5=A2=9E=E5=8A=A0=E4=BA=86J?= =?UTF-8?q?oin=E5=87=BD=E6=95=B0=20[Mod]=20=E5=B0=86processReq=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E4=BF=9D=E6=8A=A4=E6=96=B9=E6=B3=95=EF=BC=9A=E6=94=B9?= =?UTF-8?q?=E5=90=8D=E4=B8=BA=5FprocessReq?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/network/RestClient.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/vnpy/network/RestClient.py b/vnpy/network/RestClient.py index 9905bc44..a1f5c06e 100644 --- a/vnpy/network/RestClient.py +++ b/vnpy/network/RestClient.py @@ -127,6 +127,16 @@ class RestClient(object): :return: """ self._active = False + + #---------------------------------------------------------------------- + def join(self): + """ + 等待所有请求处理结束 + 如果要并确保RestClient的退出,请在调用stop之后紧接着调用join。 + 如果只是要确保所有的请求都处理完,直接调用join即可。 + :return: + """ + self._queue.join() #---------------------------------------------------------------------- def addReq(self, method, path, callback, @@ -160,7 +170,10 @@ class RestClient(object): while self._active: try: req = self._queue.get(timeout=1) - self.processReq(req, session) + try: + self._processReq(req, session) + finally: + self._queue.task_done() except Empty: pass @@ -202,7 +215,7 @@ class RestClient(object): sys.excepthook(exceptionType, exceptionValue, tb) #---------------------------------------------------------------------- - def processReq(self, req, session): # type: (Request, requests.Session)->None + def _processReq(self, req, session): # type: (Request, requests.Session)->None """处理请求""" try: req = self.beforeRequest(req)