Wouldn't is be simpler to re-write your main-loop code to be a function that you call over and over again, and then call that from the function that you pass to runsimple...
It's guaranteed not to fully satisfy your requirements, but if you're in a rush, it might be easiest.