From d36cb6500495677e7c4fb4e1704519149823a491 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Wed, 28 Jul 2021 21:46:22 +0200 Subject: [PATCH] multithreading --- panxy.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/panxy.py b/panxy.py index f73ed6f..067918b 100644 --- a/panxy.py +++ b/panxy.py @@ -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')