Right now I have a for
loop that loops through a list, usually this list is 100-500 items long. In the for
loop, a new thread is opened per item. So right now my code looks like this:
threads = []
for item in items:
t = threading.Thread(target=myfunction, args=(item,))
threads.append(t)
t.start()
But I don't want to start a new thread per, seeing it only takes a few seconds MAX per thread to execute myfunction. I want to do my loop still, calling upon myfunction with each item in argument. But to close the thread once it's done, and allow another one to take over. The max number of threads I want to open is no less than 3, no more than 20. Although if it's easier, that range can vary. I just don't want to open up a new thread each item in the loop.
For those that are curious, and if it matters. myfunction is a function that I defined that uses urllib to send a post request to a site.
I'm new to python, but I'm not new to coding all together. Sorry for the noob question.