Sorry if this is a stupid question. I am trying to use several multithreading classes to complete different tasks, which involves reusing these multithreads at different times. But I'm not sure which method to use. The code is as follows:
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 get all threads in the entire WorkerList to start working at the same time, or at least start at about the same time. Once once they were all stopped, I would like to call all threads again.
If there was no loop, I can just use .start; but since I can only start the thread once, starting does not seem to fit here. If I use run, it seems that all threads start sequentially, not only threads in the same list, but also threads from different lists.
Can anybody help?
source share