JavaScript
- 4 ответа
- 0 вопросов
4
Вклад в тег
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)
$(document).ready(function () {
$('.Add').click(function(event){
_wrapper = $(this).closest('.wrapper');
sendPost('/add?id=' + $(this).attr('docId'), function(){
console.log(window.myAdd);
_wrapper.find('.Add').hide();
_wrapper.find('.Del').show();
});
});
$('.Del').click(function(event){
_wrapper = $(this).closest('.wrapper');
sendPost('/del?id=' + $(this).attr('docId'), function(){
_wrapper.find('.Add').show();
_wrapper.find('.Del').hide();
});
});
function sendPost(url, action){
$.post(url, function (data) {
if (data.result == true) {
action();
}
});
}
});