Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
urls = list of urls

with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
    futures = [executor.submit(process_url, url) for url in urls]

    for future in concurrent.futures.as_completed(futures):
        result = future.result()
        print(result)
        if result == 403:
            # do something else without using ThreadPoolExecutor


What I have tried:

Is there a way to set conditions when using ThreadPoolExecutor? For example I'm calling a process_url functions that returns a statuscode, when It is a 403 statuscode for example, I want to do something else without ThreadPoolExecutor. The provided code only checks the response when the whole list of urls is being processed.
Posted

1 solution

Here you find a guide about ThreadPoolExecutor
ThreadPoolExecutor in Python: The Complete Guide - Super Fast Python[^]
 
Share this answer
 
Comments
Member 13554627 26-Mar-24 4:02am    
Thanks! I think my answer is in there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900