with concurrent.futures.ThreadPoolExecutor(maxworkers=100) as executor:…
- User
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: print(f"{len(cookies)} sessions generated, sending {NUM_REQUESTS} attempts to each session for a total of {len(cookies)*NUM_REQUESTS} attempts") results = executor.map(test_session, cookies)
Lets say I have 2 cookies. I want to run the "test_session" function as many times as there are cookies multiplied by num_requests. How?
- Assistant
To achieve the desired functionality of running the
test_sessionfunction a number of times equal to the total of cookies multiplied byNUM_REQUESTS, you can create a list of arguments to pass to theexecutor.map. Each argument should represent a unique session attempt.Here's how you can modify your code to execute for each cookie, for the specified number of requests:
- User
pick random from a list python
- Assistant
To pick a random item from a list in Python, you can use the
randommodule, which provides a convenient function calledchoice. Here's a simple example of how to do this:import random # Sample list my_list = ['apple', 'banana', 'cherry', 'date', 'elderberry'] # Pick a random item from the list random_item = random.choice(my_list) print(f'Randomly selected item: {random_item}')Explanation:
- Importing the Module: First, import the
randommodule. - List Definition: Define a list of items from which you want to select a random item.
- Choosing an Item: Use to select a random item from the list.
- Importing the Module: First, import the
- User
executor.map parameters?
- Assistant
- User
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: print(f"Solving {len(proxies)} captchas") results = executor.map(complete_captcha, proxies)
The function im trying to call has 0 positional arguments. do i have to set one to use this?
- Assistant
- User
with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: print(f"Solving {len(proxies)} captchas") futures = [executor.submit(complete_captcha) for _ in proxies]
As simple as possible, how do i store the results / returned values? perhaps directly in the futures line
- Assistant
To store the results returned by the
complete_captchafunction when you useexecutor.submit, you can directly capture the returned values from eachfutureobject. Here's a straightforward way to do that:Storing Results from
executor.submitYou can create a list comprehension that collects the results by calling
.result()on each future. Here's how you can do it in a simple manner:import concurrent.futures def complete_captcha(): # Example captcha solving code return "Captcha solved" proxies = ['proxy1', 'proxy2', 'proxy3'] # Example proxy list with concurrent.futures.ThreadPoolExecutor(max_workers=100) as executor: print(f"Solving {len(proxies)} captchas") # Submit tasks and store futures futures = [executor.submit(complete_captcha) for _ in proxies] # Collect results from futures results = [future.result() for future in futures] # Print the results print("Results:", results)