experiments on generating timeout events using yield and todolist

parent fcf5ced4
class Generator:
def __init__(self):
# self.todoList = [self.gen]
self.todoList = [(0, 0)]
#LIST OF GENERATOR OBJECTS OF METHODS
#generator object of self task creating method genrefer
self.refGen = self.genRefer("+")
def gen(self):
x = 0
count = 0
while True:
# print("generator : ", todoList)
self.todoList.insert(0, (count, x))
count += 1
self.todoList.insert(0, (count, x))
count += 1
self.todoList.insert(0, (count, x))
count += 1
yield x
x += 1
def genRefer(self,dot):
'''
THis method adds itself to to-do list by use of its own generator object which will be unique for different instances of generator class
:return:
'''
print("Gen refer Started",dot)
x = 0
count = 0
# while True:
while x<5:
# print("generator : ", todoList)
self.todoList.insert(0, (count, self.refGen))
count += 1
self.todoList.insert(0, (count, self.refGen))
count += 1
yield x
print("------",x)
x += 1
# return
def callgenRefer(self,dot):
'''this adapter method wil ensure that gen refer stats executing as soon as it is called by user, so only call this method not to genRefer from outside of this class'''
self.refGen = self.genRefer(dot)
next(self.refGen)
def testGeneratorClass():
ob = Generator()
m = ob.gen()
while True:
print("tester : " , ob.todoList)
time.sleep(5)
if len(ob.todoList):
i = next(m)
task = ob.todoList.pop(-1)
print(task)
print(i)
def testSelfReferGen():
'''
THis function test , If a generator method of a class can add itself to todolist and can be invoked by others with same context as yielded itself
IN this case all generator methods of a class has to generate there own generator object object at the time of instantiating the class
:return:
'''
print("Started testSelfReferGen")
ob = Generator()
print("Created Generator object")
ob.callgenRefer("*")
ob.todoList = [(0,ob.refGen)]
while True:
print("tester : " , ob.todoList)
time.sleep(5)
if len(ob.todoList):
#popoing task from to-do list and performing that task
task = ob.todoList.pop(-1)
print(task)
i = next(task[1])
print(i)
todoList = []
import time
def gen():
global todoList
x=0
count = 0
while True:
# print("generator : ", todoList)
print()
todoList.insert(0,(count,x))
count+=1
todoList.insert(0, (count, x))
count += 1
todoList.insert(0, (count, x))
count += 1
yield x
x += 1
def testclassLessGenerator():
global todoList
todoList = [(0,0)]
m = gen()
while True:
print("tester : " , todoList)
time.sleep(5)
if len(todoList):
i = next(m)
task = todoList.pop(-1)
print(task)
print(i)
if __name__ == '__main__':
# testSortition()
# testVerifyVRF()
# testVerifySort(
# testclassLessGenerator()
# testGeneratorClass()
testSelfReferGen()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment