I'm sorry if it is a stupid question. I am trying to use a number of classes of multi-threading to finish different jobs, which involves invoking these multi-threadings at different times for many times. But I am not sure which method to use. The code looks like this:
class workers1(Thread): def __init__(self): Thread.__init__(self) def run(self): do some stuff class workers2(Thread): def __init__(self): Thread.__init__(self) def run(self): do some stuff class workers3(Thread): def __init__(self): Thread.__init__(self) def run(self):do some stuff WorkerList1=[workers1(i) for i in range(X)]
WorkerList2=[workers2(i) for i in range(XX)]
WorkerList2=[workers3(i) for i in range(XXX)] while True: for thread in WorkerList1: thread.run (start? join? or?)for thread in WorkerList2: thread.run (start? join? or?) for thread in WorkerList3: thread.run (start? join? or?) do sth .
I am trying to have all the threads in all the WorkerList to start functioning at the same time, or at least start around the same time. After sometime once they were all terminated, I would like to invoke all the threads again.
If there were no loop, I can just use .start; but since I can only start a thread once, start apparently does not fit here. If I use run, it seems that all the threads start sequentially, not only the threads in the same list, but also threads from different lists.
Can anyone please help?