파이썬 스레드를 사용하여 웹 사이트 IP 주소를 확인하고 있습니다. 이것은 해결을위한 내 작업자 프로세스입니다. 이것은 데몬 스레드입니다.파이썬 스레드가 컴퓨터를 고정시키고있는 것 같습니다.
def get_ip_worker():
"""This is the worker (thread) process for parsing ips, this process takes domain from the q processes it
and then saves it to another q"""
socket.setdefaulttimeout(3)
while True:
domain = domains_q.get()
try:
addr_info = socket.getaddrinfo(domain, 80, 0, 0, socket.SOL_TCP)
for family, socktype, proto, name, ip in addr_info:
if family == 2: #okay it's ipv4
ip, port = ip
processed_q.put((ip, domain))
elif family == 10: #okay it's ipv6
ip, port, no_1, no_2 = ip
processed_q.put((ip, domain))
except:
pass
#print 'Socket Error'
domains_q.task_done()
EDIT : 도메인 domains_q.get =() 블록 아이템까지이 줄 대기열 가능하다.
이 문제는 300 스레드에서 실행하면로드 평균은 괜찮은 것처럼 보이지만 간단한 ls -la는 5 초가 걸리고 모든 것이 느립니다. 나는 어디로 잘못 갔는가? 비동기 또는 다중 처리를 사용해야합니까?
빈 큐 예외가 루프를 깨뜨리는 것이 확실합니까? – andsoa
domains_q.get()이 행은 항목을 사용할 수있을 때까지 차단됩니다. 게시물에 추가했습니다. – nacholibre