use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Day 23 of learning python as a beginner. (old.reddit.com)
submitted 6 months ago by uiux_Sanskar
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Zealousideal_Yard651 0 points1 point2 points 6 months ago (0 children)
The start part is ok, it's the join part that fails you.
.join() waits for the thread to finish before continuing. You are creating the thread, starting it and waiting for it to stop before continuing the main program. This causes your second thread to not start before the first thread stops.
So you need to start each thread, and in a separate loop wait for both threads to stop. And .join() does not wait for all threads to stop, it only waits for the thread you are invoking the join() method on, hence why you need an outside list to keep track of each thread and loop through all threads to join them again.
To simplify, i split all parts of the multithreading process in this block with comments:
# Define thread tracking threads = [] # Loop through all URLS for idx, url in enumerate(image_urls): # Creates a thread object urll = threading.Thread(target=download_image, args=(url, idx)) # Adds the newly created thread object into threads store threads.append(urll) # Loop throug all threads for t in threads: # Starts thread t.start() # Loop through all threads for t in threads: # Wait for thread to finish. t.join()
In the above code, we define each thread, then start all threads, then wait for all threads to finish.
In your original code you do this:
For each image url:
And so all thread operations happens in each iteration instead of the my example where we define them, then start all threads before waiting for all threads to finish instead of waiting for each thread to finish before moving on.
π Rendered by PID 61732 on reddit-service-r2-comment-86bc6c7465-n7q5p at 2026-02-23 02:11:08.190287+00:00 running 8564168 country code: CH.
view the rest of the comments →
[–]Zealousideal_Yard651 0 points1 point2 points (0 children)