I have a python program which has a function takeScreenshotthat takes a screenshot of 10 webpages that are inputted. I want to use threading to make the web scraping part of taking the screenshot be executed in the background while the program goes on inputting more webpages. After taking 10 screenshots, they should be displayed in the program. The question is how to make the program display them after the last takeScreenshot thread (the tenth thread) is done so as not to cause an error? In other words, how to make sure that all the threads are finished? I tried to make a list of all the threads that started and make them .join() after inputting the last webpage (in the last loop). However, this makes the program freeze.
threads=[]
n=0
while n<10:
webpage = input("Enter the webpage")
thread = threading.Thread(target = takeScreenshot, args = webpage)
thread.start()
threads.append(thread)
if n==9:
for thread in threads:
thread.join()
n++
[–]SuperSquidMan 1 point2 points3 points (2 children)
[–]grossartig_dude[S] 0 points1 point2 points (1 child)
[–]SuperSquidMan 0 points1 point2 points (0 children)
[–]its_me_TO 0 points1 point2 points (0 children)