class Worker(threading.Thread):

    def __init__(self):
        threading.Thread.__init__()
self.run_event = threading.Event()

def run(self):
    self.run_event.wait()
while self.run_event.is_set():
    pass
End a loop in a function from another function in python