>>> key = u'AIzaSyDDRQjJN5IIrMzl4i9Po670KmuKP5ENAhM'
>>> url = u'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?key=%s&language=ru&input=Феодосия' % key
>>> response = urllib2.urlopen(url)
>>> data = json.loads(response.read())
>>> data
>>> numbers = [1, 1, 1, 3, 3, 2, 2, 15, 20, 2, 1]
>>> import itertools
>>> total = []
>>> num_len = len(numbers) + 1
>>> for i in range(2, num_len):
num_comb = list(itertools.combinations(numbers, i))
total += num_comb
>>> total = ((i, sum(i)) for i in total if sum(i) > 10)
>>> min_total = min(total, key=lambda x: x[1])
>>> min_total
((1, 3, 3, 2, 2), 11)
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)
Просто совет из личного опыта. Мне как то помог sleep от случайного значения