Created
May 8, 2015 00:49
-
-
Save lalomartins/a1eff40649d6ef91eef6 to your computer and use it in GitHub Desktop.
test for mysterious Loop() method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import time | |
done = [False] | |
class Test(object): | |
def __init__(self): | |
self.loopfunctions = [] | |
def SetLoopCallback(self, function): | |
self.loopfunctions.append(function) | |
def Update(self): | |
print('updated') | |
def Loop(self, maximum=0): | |
i=0 | |
while not done[0]: | |
self.Update() | |
for f in self.loopfunctions: | |
f(self) | |
if maximum: i+=1 | |
if i > maximum: | |
done[0] = True | |
def dummy(test): | |
time.sleep(0.3) | |
test = Test() | |
test.SetLoopCallback(dummy) | |
test.SetLoopCallback(dummy) | |
test.SetLoopCallback(dummy) | |
print('entering loop for 5 cycles') | |
test.Loop(5) | |
print('done with first loop, entering endless') | |
done[0] = False | |
test.Loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment