![]() |
RuntimeError: generator raised StopIteration - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: RuntimeError: generator raised StopIteration (/thread-33093.html) |
RuntimeError: generator raised StopIteration - quest - Mar-28-2021 Hello, I created this class: class ssource: def __init__(self, n): self.list1=[] self.list2=[] self.i=0 self.max=n self.At=stream(self, self.list1) self.Bt=stream(self, self.list2) def __next__(self): if self.i>=self.max: raise StopIteration print(f"NEXTSYNC:{self.i}") self.list1.append(f'A{self.i}') self.list2.append(f'B{self.i}') self.i += 1And I am testing my class with this code script: src=ssource(10) Ai=src.Ait Bi=src.Bit for i in range(5): print(f'A->{next(Ai)}') for i in range(8): print(f'B->{next(Bi)}') for a in Ai : print(f'A->{a}')And I am getting this error: here is my another functiondef stream(src, flist): try: while True: while len(flist)==0: next(src) yield(flist.pop(0)) except StopIteration: pass # raise StopIteration RE: RuntimeError: generator raised StopIteration - quest - Mar-28-2021 Hello again, I did nothing but now it is ok. I am studying on jupyter notebook maybe because of some connection problems I got this error. OR If you have any idea, you are very welcome but it is not ok and I do not know how it is ok |