Skip to content

Commit b29c03a

Browse files
committed
修复获取ip的Server头部数据挂住的问题
1 parent a222fa1 commit b29c03a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

checkip.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@
3131
else:
3232
from Queue import Queue, Empty
3333
import time
34-
34+
from time import sleep
35+
3536
g_useOpenSSL = 1
3637
g_usegevent = 1
3738
if g_usegevent == 1:
3839
try:
3940
from gevent import monkey
4041
monkey.patch_all()
4142
g_useOpenSSL = 0
43+
from gevent import sleep
4244
except ImportError:
4345
g_usegevent = 0
4446

@@ -120,7 +122,7 @@
120122
"ip_tmperror.txt,格式:ip"
121123
g_autodeltmperrorfile = 0
122124

123-
logging.basicConfig(format="[%(process)d][%(threadName)s]%(message)s",level=logging.INFO)
125+
logging.basicConfig(format="[%(threadName)s]%(message)s",level=logging.INFO)
124126

125127
def PRINT(strlog):
126128
logging.info(strlog)
@@ -433,12 +435,17 @@ def getgooglesvrname(self,conn,sock,ip):
433435
infds, outfds, errfds = select.select([sock, ], [], [], g_conntimeout)
434436
if len(infds) == 0:
435437
break
438+
trycnt = 0
436439
while True:
437440
try:
438441
d = conn.read(1024)
439442
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)
442449
pass
443450
data = data + d.replace("\r","")
444451
index = data.find("\n\n")
@@ -589,6 +596,7 @@ def checksingleprocess(ipqueue,cacheResult,max_threads):
589596
break
590597
threadlist.append(ping_thread)
591598
evt_ready.wait()
599+
error = 0
592600
try:
593601
time_begin = time.time()
594602
logtime = time_begin
@@ -603,11 +611,10 @@ def checksingleprocess(ipqueue,cacheResult,max_threads):
603611
time_begin = time_end
604612
lastcount = count
605613
else:
606-
if time_end - time_begin > g_handshaketimeout * 3:
614+
if time_end - time_begin > g_handshaketimeout * 5:
607615
dumpstacks()
608-
break;
609-
else:
610-
time_begin = time_end
616+
error = 1
617+
break
611618
if time_end - logtime > 60:
612619
PRINT("has thread count:%d,ip total cnt:%d" % (Ping.getCount(),queuesize))
613620
logtime = time_end
@@ -616,8 +623,9 @@ def checksingleprocess(ipqueue,cacheResult,max_threads):
616623
except KeyboardInterrupt:
617624
PRINT("need wait all thread end...")
618625
evt_finish.set()
619-
for p in threadlist:
620-
p.join()
626+
if error == 0:
627+
for p in threadlist:
628+
p.join()
621629
cacheResult.close()
622630

623631

0 commit comments

Comments
 (0)