#generator object of self task creating method genrefer
self.refGen=self.genRefer("+")
defgen(self):
x=0
count=0
whileTrue:
# 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
yieldx
x+=1
defgenRefer(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:
whilex<5:
# print("generator : ", todoList)
self.todoList.insert(0,(count,self.refGen))
count+=1
self.todoList.insert(0,(count,self.refGen))
count+=1
yieldx
print("------",x)
x+=1
# return
defcallgenRefer(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)
deftestGeneratorClass():
ob=Generator()
m=ob.gen()
whileTrue:
print("tester : ",ob.todoList)
time.sleep(5)
iflen(ob.todoList):
i=next(m)
task=ob.todoList.pop(-1)
print(task)
print(i)
deftestSelfReferGen():
'''
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)]
whileTrue:
print("tester : ",ob.todoList)
time.sleep(5)
iflen(ob.todoList):
#popoing task from to-do list and performing that task