Sep-03-2019, 12:00 PM
I have a problem to control the queue threads that I run.
I want to run 50 threads ( min of two numbers where 50 will be always the minimum) and when one thread is finished a new thread shall be executed so 50 threads are always running.
I added piece of my code
can anyone point me where is the issue I have?
I want to run 50 threads ( min of two numbers where 50 will be always the minimum) and when one thread is finished a new thread shall be executed so 50 threads are always running.
I added piece of my code
num_theads = min(50, len(tickers)) #set up the queue to hold all the urls #print('Thread to be prepared') q = Queue(maxsize=num_theads) #load up the queue with the urls to fetch and the index for each job (as a tuple): for ticker in tickers: #need the index and the url in each queue item. print(ticker) q.put(ticker) worker = Thread(target=processData, args=(q,table)) worker.setDaemon(True) worker.start()
def processData(q,table): while not q.empty(): ticker = q.get() //my code is here q.task_done() return Truewhen I run the code, it just go through the whole list. it seems not 50 work but more
can anyone point me where is the issue I have?