From 1a61cfae96a8121ed8bb7b47f4ffedff460da3a9 Mon Sep 17 00:00:00 2001 From: moonshawdo Date: Sat, 28 Mar 2015 02:48:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=84=9A=E6=9C=AC=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E4=B8=80=E6=AE=B5=E6=97=B6=E9=97=B4=E5=90=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E9=80=80=E5=87=BA=E7=9A=84=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- checkip.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/checkip.py b/checkip.py index c90186e..9411f4c 100755 --- a/checkip.py +++ b/checkip.py @@ -628,6 +628,7 @@ def getgooglesvrname(self,conn,sock,ip): class Ping(threading.Thread): ncount = 0 ncount_lock = threading.Lock() + ipcnt = 0 __slots__=["checkqueue","cacheResult"] def __init__(self,checkqueue,cacheResult): threading.Thread.__init__(self) @@ -644,6 +645,7 @@ def runJob(self): addrint = self.queue.get(True,2) ipaddr = to_string(addrint) self.queue.task_done() + self.addIPCount() ssl_obj = my_ssl_wrap() (ssldomain, costtime,timeout,gwsname,ssl_orgname) = ssl_obj.getssldomain(self.getName(), ipaddr) if ssldomain is not None: @@ -679,6 +681,13 @@ def getCount(): return Ping.ncount finally: Ping.ncount_lock.release() + @staticmethod + def addIPCount(): + try: + Ping.ncount_lock.acquire() + Ping.ipcnt += 1 + finally: + Ping.ncount_lock.release() class RamdomIP(threading.Thread): @@ -897,8 +906,14 @@ def checksingleprocess(ipqueue,cacheResult,max_threads): break threadlist.append(ping_thread) try: - for p in threadlist: - p.join(5) + quit = False + while not quit: + for p in threadlist: + if p.is_alive(): + p.join(5) + elif Ping.getCount() == 0 or cacheResult.queryfinish(): + quit = True + break except KeyboardInterrupt: PRINT("try to interrupt process") ipqueue.queue.clear() @@ -955,6 +970,7 @@ def list_ping(): if g_usegevent == 1: PRINT("support gevent") + cur_time = time.time() checkqueue = Queue() cacheResult = TCacheResult() lastokresult,lasterrorresult = cacheResult.loadLastResult() @@ -976,7 +992,7 @@ def list_ping(): ip_list = cacheResult.getIPResult() ip_list.sort() - PRINT('try to collect ssl result') + PRINT('try to collect ssl result,check ip cnt: %d,times:%ds' % (Ping.ipcnt,time.time()-cur_time) ) op = 'wb' if sys.version_info[0] == 3: op = 'w'