I use several threads with child-threads. Now i want to stop a parent-thread or wait until a parent thread has done its work without checking and stopping all the child threads. My thought is to wrap the parent thread with a process and then just to terminate the process, which seems to terminate the corresponding parent-thread with all its childs.
def worker(conn):
#this is the class including the parent thread
xi = Test_Risk_Calc('99082')
#start working
xi.test()
#finished
print ('EVERYTHING IS DONE, BUT CHILD THREADS ARE STILL ALIVE')
conn.send('EXIT SEND')
return
def main():
parent_conn, child_conn = Pipe()
p = multiprocessing.Process(target=worker, args=(child_conn,))
p.start()
#wait for finished parent-thread
print(parent_conn.recv())
p.terminate()
p.join()
print('JOINED, PROCESS AND ALL ITS THREADS ARE TERMINATED')
return
I am not sure if this is a proper way to solve the problem