2018-09-27 21:35:37 -04:00
|
|
|
# outer generator ignores a thrown GeneratorExit (this is allowed)
|
2017-01-16 08:17:44 -05:00
|
|
|
|
2016-12-19 20:57:39 -05:00
|
|
|
def gen():
|
|
|
|
try:
|
|
|
|
yield 123
|
|
|
|
except GeneratorExit:
|
|
|
|
print('GeneratorExit')
|
2018-09-27 21:35:37 -04:00
|
|
|
|
|
|
|
def gen2():
|
|
|
|
try:
|
|
|
|
yield from gen()
|
|
|
|
except GeneratorExit:
|
|
|
|
print('GeneratorExit outer')
|
|
|
|
yield 789
|
|
|
|
|
2017-01-16 08:17:44 -05:00
|
|
|
# thrown a class
|
2018-09-27 21:35:37 -04:00
|
|
|
g = gen2()
|
2016-12-19 20:57:39 -05:00
|
|
|
print(next(g))
|
2017-01-16 08:17:44 -05:00
|
|
|
print(g.throw(GeneratorExit))
|
|
|
|
|
|
|
|
# thrown an instance
|
2018-09-27 21:35:37 -04:00
|
|
|
g = gen2()
|
2017-01-16 08:17:44 -05:00
|
|
|
print(next(g))
|
|
|
|
print(g.throw(GeneratorExit()))
|