I want five functions to run concurrently using python threading. Each of these functions returns a value. I want to get the return values of these functions once they complete their work. I implemented the below code that waits for threads to join sequentially. In other words, when the code is waiting for thread1
to join, thread2
might complete its work and return a value. But, I want first to get the first thread return value that completed its work and second get the second thread that completed its work, and so on.
threads = []
for user in users:
task = threading.Thread(target=monitor_wrapper, args=(user[0], user[1]))
threads.append(task)
task.start()
time.sleep(delay / len(users))
for thread in threads:
result = thread.join()
print(result)
I read something about Queue
regarding this matter.