gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
with concurrent.futures.ThreadPoolExecutor(maxworkers=100) as executor: futures =…
- User
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: futures = {executor.submit(login_attempt,captcha): captcha for captcha in captchas}
How to print the contents of the future?
- Assistant
To print the result of each
Futureobject in thefuturesdictionary that you have created with theThreadPoolExecutor, you can use theconcurrent.futures.as_completedfunction. This function returns an iterator that yields futures as they complete.Here's how you might modify your code to print the contents of each future after they complete:
import concurrent.futures # Assuming you have your login_attempt function defined and captchas is a list of captcha values with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: futures = {executor.submit(login_attempt, captcha): captcha for captcha in captchas} # Iterate over the futures as they complete for future in concurrent.futures.as_completed(futures): captcha = futures[future] # Get the captcha associated with this future try: result = future.result() # Get the result of the future # Print the result, replace `result` with any message you want to print print(f'Captcha: {captcha}, Result: {result}') except Exception as e: print(f'Captcha: {captcha} generated an exception: {e}')