Beispiel #1
0
def setupForceQuiescence(module, function):
    quiescent = threading.Event()
    quiescent.clear()
    can_continue = threading.Event()
    can_continue.clear()

    def stub(*args, **kwargs):
        #We do not want to suspend if we are in a recursive call
        callers = [x[3] for x in inspect.stack()[1:]]
        if function.__name__ in callers:
            return function(*args, **kwargs)
        can_continue.wait()
        return getattr(module, function.__name__)(*args, **kwargs)

    class QuiescenceWatcher(threading.Thread):
        def __init__(self):
            self.watching = True
            super(QuiescenceWatcher, self).__init__()
            self.name = function.__name__ + " watcher"

        def run(self):
            while self.watching and isFunctionInAnyStack(function):
                time.sleep(sleep_time)
            quiescent.set()

    watcher = QuiescenceWatcher()
    redefineFunction(module, function, stub)
    watcher.start()
    return quiescent, can_continue, watcher
Beispiel #2
0
def cleanFailedForceQuiescence(can_continue, watcher, module, function):
    """cleans up if failed to force quiescence. Function is the original
    function"""
    #First we stop the watcher
    watcher.watching = False
    #Then we switch back the the function to remove the stub
    redefineFunction(module, function, function)
    #Now, we can makeevryone leave the stub
    can_continue.set()
Beispiel #3
0
 def apply(self):
     redefineFunction(main, main.func_v1, func_v2)
Beispiel #4
0
 def apply(self):
     redefineFunction(main, main.sum, sum_v2)
     all_data = DataAccessor(main.Data, "immediate")
     for d in all_data:
         updateToClass(d, main.Data, Data_v2, transformer)
     redefineClass(main, main.Data, Data_v2)
Beispiel #5
0
 def apply(self):
     redefineFunction(main, main.hello, hello_v2)
Beispiel #6
0
 def apply(self):
     redefineFunction(main, main.tic, tic_v2)
     redefineFunction(main, main.tac, tac_v2)