Можно в треды пустить
from threading import Thread
import httplib, sys
from queue import Queue
urls = ['url1', 'url2',.....]
concurrent = 200
def doWork():
while True:
url = q.get()
status, url = getStatus(url)
doSomethingWithResult(status, url)
q.task_done()
def getStatus(url):
try:
proxyRand = getRandProxy()
conn = httplib.HTTPConnection(proxyRand["ip"], proxyRand["port"])
conn.request("GET", url, headers={})
res = conn.getresponse()
return res.status, url
except Exception as e:
return e, url
def getRandProxy():
return {
"ip" : "127.0.0.1",
"port" : 80
}
def doSomethingWithResult(status, url):
print(status, url)
q = Queue(concurrent * 2)
for i in range(concurrent):
t = Thread(target=doWork)
t.daemon = True
t.start()
try:
for url in urls:
q.put(url.strip())
q.join()
except KeyboardInterrupt:
sys.exit(1)