How to run an infinite while-loop with parallel threads [duplicate]

I am trying to run an infinte while loop in my main thread with another parallel thread that is started and stopped/deleted in each iteration without affecting the while loop. The challenge is that the main thread must not wait for the parallel thread, i.e. it should start the next iteration regardless of whether the parallel thread in this iteration has already finished.

My main looks like that:

while true
 # start iteration and do something

 # start parallel thread
 parallel_thread = threading.Thread(target=parallel_thread_class.thread_do_something(), daemon = True)
 parallel_thread.start()

 # end iteration and start new one

At the moment, the main thread (while loop) waits until the method parallel_thread_class.thread_do_something() has finished before it finishes the current iteration.


the brackets in parallel_thread_class.thread_do_something() calls the function in the main thread, remove the brackets to have the constructed thread call the function as follows

 parallel_thread = threading.Thread(target=parallel_thread_class.thread_do_something, daemon = True)