accept interrupt, shorter timeout

master
Felix Pankratz 4 years ago
parent eb8dd6db76
commit cea5062d10

@ -29,7 +29,7 @@ def test_proxy(prx):
proxy_handler = request.ProxyHandler({'https': 'http://' + prx + '/', 'http': 'http://' + prx + '/' }) proxy_handler = request.ProxyHandler({'https': 'http://' + prx + '/', 'http': 'http://' + prx + '/' })
opener = request.build_opener(proxy_handler) opener = request.build_opener(proxy_handler)
try: try:
result = opener.open(target, timeout=10) result = opener.open(target, timeout=6)
content = result.read().decode() content = result.read().decode()
print(srv_string + 'ok. \u2705') print(srv_string + 'ok. \u2705')
return True return True
@ -51,13 +51,18 @@ def get_proxies():
proxy_list = get_list_from_api() proxy_list = get_list_from_api()
working_list = [] working_list = []
start_length = len(proxy_list) start_length = len(proxy_list)
for entry in proxy_list: try:
if test_proxy(entry): for entry in proxy_list:
working_list.append(entry) if test_proxy(entry):
else: working_list.append(entry)
pass else:
print('{}/{} new proxies ready.'.format(len(working_list), start_length)) pass
return working_list except KeyboardInterrupt:
print(' Impatient? Interrupt again to terminate')
finally:
print('{}/{} new proxies ready.'.format(len(working_list), start_length))
return working_list
def user_loop(): def user_loop():
proxies = [] proxies = []

Loading…
Cancel
Save