Python Forum
Having Trouble With Threading - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Having Trouble With Threading (/thread-6562.html)



Having Trouble With Threading - digitalmatic7 - Nov-28-2017

This code isn't throwing errors, instead it's only giving me limited results based on "for i in range(20)" line. If I have it set as '20' it will only scrape 20 results, if I change it to '10' it will give me 10 etc.

It's ignoring the while loop requirements and I can't figure out why.

The script requires a test.csv file in working dir, here are some URLs: https://pastebin.com/TNYDBvTF

EXPAND CODE:



RE: Having Trouble With Threading - Larz60+ - Nov-28-2017

Suggest you take a gander at: https://pymotw.com/3/threading/

You'll probably be interested in: greenteapress.com/semaphores/LittleBookOfSemaphores.pdf
also as it shows how to communicate between threads


RE: Having Trouble With Threading - digitalmatic7 - Nov-29-2017

threads = []
for i in range(5):
    t = threading.Thread(target=worker, args=(i,))
    threads.append(t)
    t.start()
Does this code only generate the number of threads, or does it also automatically assign them to the project as well?

Am I having a problem with variables inside the main loop conflicting with the threads or is it a problem of not assigning threads properly or..? Where specifically am I not setting this up correctly?