invoking yield for a generator in another function
问题 suppose I have some manager object. This object's API has a main_hook function, that gets another function f as it's argument, and runs the given f in a loop, doing some stuff in between each iteration: def main_hook(self,f): while (self.shouldContinue()): #do some preparations f(self) #do some tear down Now, I also have (more accurately, would like to have ) a function stop_and_do_stuff , that once called, stops main_hook dead in it's tracks, returns the control to whichever func called main