join() threads without holding the main thread in python
Question: I have a code that calls to threads over a loop, something like this:

    
    
    def SubmitData(data):
        # creating the relevant command to execute
        command = CreateCommand(data)
        subprocess.call(command)
    
    def Main():
        while(True):
            # generating some data
            data = GetData()
            MyThread = threading.Thread(target=SubmitData,args=(data,)) 
            MyThread.start()
    

obviously, I don't use `join()` on the **threads**. My question is how to
`join()` those **threads** without making the main thread wait for them? Do I
even need to `join()` them? what will happend if I won't `join()` them?

some important points:

  * the _while_ loop is suppose to for a very long time (couple of days)
  * the _command_ itself is not very long (few seconds)

I'm using threading for Performance so if someone have a better idea instead,
I would like to try it out.


Answer: `Popen()` doesn't block. Unless `CreateCommand()` blocks, you could call
`SubmitData()` in the main thread:

    
    
    from subprocess import Popen
    
    processes = []
    while True:
        processes = [p for p in processes if p.poll() is None] # leave only running
        processes.append(Popen(CreateCommand(GetData()))) # start a new one
    

* * *

> Do I even need to join() them? what will happend if I won't join() them?

No. You don't need to join them. All non-daemonic threads are joined
automatically when the main thread exits.

