I would highly recommend using the viztask module to control the flow of your program. Each stage would be implemented as a task and the main function would just yield each stage one after the other:
Code:
def stage1():
while SomeCondition:
#Do something each frame here
#Wait for next frame
yield None
def stage2():
while SomeCondition:
#Do something each frame here
#Wait for next frame
yield None
def main():
#Execute stage 1 and wait for it to finish
yield stage1()
#Execute stage 2 and wait for it to finish
yield stage2()
viztask.schedule(main())
There are a lot of examples in the docs showing how to use the viztask module. You can also ask here on the forum if you have more specific questions about it.