1# outer generator ignores a thrown GeneratorExit (this is allowed) 2 3def gen(): 4 try: 5 yield 123 6 except GeneratorExit: 7 print('GeneratorExit') 8 9def gen2(): 10 try: 11 yield from gen() 12 except GeneratorExit: 13 print('GeneratorExit outer') 14 yield 789 15 16# thrown a class 17g = gen2() 18print(next(g)) 19print(g.throw(GeneratorExit)) 20 21# thrown an instance 22g = gen2() 23print(next(g)) 24print(g.throw(GeneratorExit())) 25