multithreading

master
Felix Pankratz 3 years ago
parent cfe8e578b8
commit d36cb65004

@ -33,33 +33,37 @@ def test_proxy(prx):
content = result.read().decode()
if prx.split(':')[0] not in content:
print(srv_string + 'bait.')
return False
return False, prx
print(srv_string + 'ok. \u2705')
return True
return True, prx
except error.HTTPError:
print(srv_string + 'fail. \u274c')
return False
return False, prx
except error.URLError:
print(srv_string + 'down! \u2935')
return False
return False, prx
except RemoteDisconnected:
print(srv_string + 'connection fail!')
return False
return False, prx
except socket.timeout:
print(srv_string + 'timeout! \u23f3')
return False
return False, prx
def get_proxies():
#from threading import Thread
import concurrent.futures
proxy_list = get_list_from_api()
working_list = []
start_length = len(proxy_list)
threads = []
print('Got {} proxies.'.format(len(proxy_list)))
try:
for entry in proxy_list:
if entry not in working_list:
if test_proxy(entry):
working_list.append(entry)
else:
pass
with concurrent.futures.ThreadPoolExecutor() as executor:
stuff = [executor.submit(test_proxy, entry) for entry in proxy_list if entry not in working_list]
for f in stuff:
result = f.result()
if result[0]:
working_list.append(result[1])
except KeyboardInterrupt:
print(' Impatient? Interrupt again to terminate')

Loading…
Cancel
Save