| 53 | |
| 54 | # Check all proxies and return a working list with proxies |
| 55 | def check_proxies(args): |
| 56 | |
| 57 | proxy_queue = Queue() |
| 58 | total_proxies = len(args.proxy) |
| 59 | |
| 60 | log.info('Checking %d proxies...', total_proxies) |
| 61 | |
| 62 | proxies = [] |
| 63 | |
| 64 | for proxy in enumerate(args.proxy): |
| 65 | proxy_queue.put(proxy) |
| 66 | |
| 67 | t = Thread(target=check_proxy, |
| 68 | name='check_proxy', |
| 69 | args=(proxy_queue, args.proxy_timeout, proxies)) |
| 70 | t.daemon = True |
| 71 | t.start() |
| 72 | |
| 73 | # This is painfull but we need to wait here untill proxy_queue is completed so we have a working list of proxies |
| 74 | proxy_queue.join() |
| 75 | |
| 76 | working_proxies = len(proxies) |
| 77 | |
| 78 | if working_proxies == 0: |
| 79 | log.error('Proxy was configured but no working proxies was found! We are aborting!') |
| 80 | sys.exit(1) |
| 81 | else: |
| 82 | log.info('Proxy check completed with %d working proxies of %d configured', working_proxies, total_proxies) |
| 83 | return proxies |