I'm using some threads to compute a task in a faster way. I've seen that if one of the threads I launch raises an exception, all the other threads continue to work and the code doesn't raise that exception.
I'd like that as soon as one thread fails, all the other threads are killed and the main file raises the same exception of the thread.
My thread file is this:
from threading import Thread
class myThread(Thread):
def __init__(self, ...):
Thread.__init__(self)
self.my_variables = ...
def run(self):
# some code that can raise Exception
My main is
import MyThread
threads = []
my_list = ["a_string", "another_string", "..."]
for idx in range(len(my_list)):
threads.append(MyThread(idx = idx, ... )
for t in threads:
t.start()
for t in threads:
t.join()
I know that there are some methods to propagate the exception between the parent and the child thread as here: https://stackoverflow.com/a/2830127/12569908. But in this discussion, there is only 1 thread while I've many. In addition, I don't want to wait for all of them to end if one of them fails at the beginning. I tried to adapt that code to my case, but I still have problems.
How can I do?