256 Kilobytes

Answers in Scripting and Automation | By August R. Garcia

Published 2 months agoFri, 16 Aug 2019 06:38:19 -0700 | Last update 2 months agoMon, 26 Aug 2019 01:21:58 -0700

113 views, 0 RAMs, and 0 comments

Tags: Python, Multithreading

Profile Photo - August R. Garcia August R. Garcia LARPing as a Sysadmi... Portland, OR
🗎 198 🗨 985 🐏 299
Site 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. 🐏 ⨉ 0 Posted by August R. Garcia 2 months ago

Edit History

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

Sir, I can do you a nice SEO.

Post a New Comment

To leave a comment, login to your account or create an account.

Do you like having a good time?

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
You can also login to an existing account or recover your password. All use of this site is subject to terms outlined in the terms of service and privacy policy.