31
31
else :
32
32
from Queue import Queue , Empty
33
33
import time
34
-
34
+ from time import sleep
35
+
35
36
g_useOpenSSL = 1
36
37
g_usegevent = 1
37
38
if g_usegevent == 1 :
38
39
try :
39
40
from gevent import monkey
40
41
monkey .patch_all ()
41
42
g_useOpenSSL = 0
43
+ from gevent import sleep
42
44
except ImportError :
43
45
g_usegevent = 0
44
46
120
122
"ip_tmperror.txt,格式:ip"
121
123
g_autodeltmperrorfile = 0
122
124
123
- logging .basicConfig (format = "[%(process)d][%( threadName)s]%(message)s" ,level = logging .INFO )
125
+ logging .basicConfig (format = "[%(threadName)s]%(message)s" ,level = logging .INFO )
124
126
125
127
def PRINT (strlog ):
126
128
logging .info (strlog )
@@ -433,12 +435,17 @@ def getgooglesvrname(self,conn,sock,ip):
433
435
infds , outfds , errfds = select .select ([sock , ], [], [], g_conntimeout )
434
436
if len (infds ) == 0 :
435
437
break
438
+ trycnt = 0
436
439
while True :
437
440
try :
438
441
d = conn .read (1024 )
439
442
break
440
- except SSLError :
441
- time .sleep (0.5 )
443
+ except SSLError as e :
444
+ trycnt += 1
445
+ if trycnt > 6 :
446
+ return ""
447
+ PRINT ("try to read http response again" )
448
+ sleep (0.5 )
442
449
pass
443
450
data = data + d .replace ("\r " ,"" )
444
451
index = data .find ("\n \n " )
@@ -589,6 +596,7 @@ def checksingleprocess(ipqueue,cacheResult,max_threads):
589
596
break
590
597
threadlist .append (ping_thread )
591
598
evt_ready .wait ()
599
+ error = 0
592
600
try :
593
601
time_begin = time .time ()
594
602
logtime = time_begin
@@ -603,11 +611,10 @@ def checksingleprocess(ipqueue,cacheResult,max_threads):
603
611
time_begin = time_end
604
612
lastcount = count
605
613
else :
606
- if time_end - time_begin > g_handshaketimeout * 3 :
614
+ if time_end - time_begin > g_handshaketimeout * 5 :
607
615
dumpstacks ()
608
- break ;
609
- else :
610
- time_begin = time_end
616
+ error = 1
617
+ break
611
618
if time_end - logtime > 60 :
612
619
PRINT ("has thread count:%d,ip total cnt:%d" % (Ping .getCount (),queuesize ))
613
620
logtime = time_end
@@ -616,8 +623,9 @@ def checksingleprocess(ipqueue,cacheResult,max_threads):
616
623
except KeyboardInterrupt :
617
624
PRINT ("need wait all thread end..." )
618
625
evt_finish .set ()
619
- for p in threadlist :
620
- p .join ()
626
+ if error == 0 :
627
+ for p in threadlist :
628
+ p .join ()
621
629
cacheResult .close ()
622
630
623
631
0 commit comments