Weil die Suchfunktion der einzelnen module meines programmes sehr viel zeit in anspruch nimmt, durch sehr viele http requests, will ich sie alle durch ein thread system parrallel laufen lassen, und dann, wenn alle threads fertig gelaufen sind, die gesamten return values bekommen, von allen module.search threads
# Create threads to fasten up the search process
threads_list = list()
que = Queue(len(self.modules))
retObj = []
for index, module in enumerate(self.modules):
thread = Thread(
target=lambda q, arg1: q.put(module.search(arg1)), args=(que, title)
)
que.put(index)
threads_list.append(thread)
thread.start()
# Wait for all threads to finish
for thread in threads_list:
thread.join()
# ALl threads have finished here
result = que.get()
print(result)```
The problem is that with que.get() I only get the result of the last thread and not the result of all threads together
The line
result = que.get()is only getting one result, because it is only asking for one result!If you want a list of all the results, try this:
The 'queue' attribute of a Queue is its internal container (actually a deque). It is not documented which hints one should not use it routinely, but since all your threads have finished writing to the queue, it is quite safe to do so here.