I am writing a program that creates two new processes and must wait for them both to finish before continuing. How does one launch both processes and have the program wait for both to exit? Consider the pseudocode:
I currently have:
create_process("program1.exe").wait()
create_process("program2.exe").wait()
This is enificent as program2 can run concurently with program1.
create_process("program1.exe")
create_process("program2.exe").wait()
This may be wrong as program1 may take longer than program2.
I'm interested in a general solution, I bet there's algorithms or design patterns invented to deal with this stuff. But to add context to the question, I'm writing a Python script that calls pgsql2shp.exe twice, to export two tables from the database to the local machine and then preform an intersection. This script is written in Python 2.7 and uses subprocess.popen
How about using Threading? If you spin up a couple of threads, each thread can run independently and you can join the threads when they are completed.
Try some code like this: (This code is heavily commented so that you can follow what's going on)