|I have used python a little.....|
Because it is a "proper programming language" goto is non-existent(except for a library that was supposedly intended as a joke - haven't used it though). A while loop is normally the way to go.
You may want to have a look at the "spawn" function and it's derivatives for starting the document or possibly the options the system library offers.
As for the subroutine you may need to make function, class or something similar.
I can't help much more than that because my experience with python is lacking...