256 Kilobytes

Answers in Scripting and Automation | By August R. Garcia

Published | Last Update

212 views, 0 RAMs, and 0 comments

Tags: Python, Multithreading

Profile Photo - August R. GarciaAugust R. GarciaLARPing as a Sysadmi...Portland, ORSite Owner

Self explanatory, mostly.

Original Code

import Queue
from   threading import Thread, active_count

import time

que       = Queue.Queue() 
threads   = list()  
for p in proxy_arr:
        t  = Thread(  target=lambda q, p, url_for_test   : q.put(proxy_obj_init(p, url_for_test)), args=(que, p, url_for_test  ))

        threads.append(t)
        t.start() 

# Wait for all proxies to finish testing 
for index, thread in enumerate(threads):
        thread.join()

With Thread Monitor

import Queue
from   threading import Thread, active_count

import time

que       = Queue.Queue() 
threads   = list()  
for p in proxy_arr:
        t  = Thread(  target=lambda q, p, url_for_test   : q.put(proxy_obj_init(p, url_for_test)), args=(que, p, url_for_test  ))

        threads.append(t)
        t.start() 

# Wait for all proxies to finish testing 
# active_count() includes the main thread, so if there are no remaining threads,
# it will return 1 (not 0)
# rjust is used to make sure the string is the same length on each write,
# Otherwise, there may be characters that are not cleared from the previous loop 
while ( active_count() > 1 ):
        sys.stdout.write("> Waiting on " + str(active_count()).rjust(5, " ") + " proxy threads to finish...\r" )
        sys.stdout.flush()
        time.sleep(0.5)

Download more RAM. 🐏 ⨉ 0Posted by August R. Garcia 9 months ago

Edit History

• [2019-08-16 6:38 PDT] August R. Garcia (9 months ago)
🕓 Posted at 16 August, 2019 06:38 AM PDT

Sir, I can do you a nice SEO.

Post a New Comment

Do you like having a good time?

Register an Account

You can also login to an existing account or reset your password. All use of this site is subject to the terms of service and privacy policy.

Read Quality Articles

Read some quality articles. If you can manage to not get banned for like five minutes, you can even post your own articles.

View Articles →

Argue with People on the Internet

Use your account to explain why people are wrong on the Internet forum.

View Forum →

Vandalize the Wiki

Or don't. I'm not your dad.

View Wiki →

Ask and/or Answer Questions

If someone asks a terrible question, post a LMGTFY link.

View Answers →

Make Some Money

Hire freelancers and/or advertise your goods and/or services. Hire people directly. We're not a middleman or your dad. Manage your own business transactions.

Register an Account

Answers— Read More

Find more related content below!