2017-01-16 08:17:44 -05:00
|
|
|
# generator ignores a thrown GeneratorExit (this is allowed)
|
|
|
|
|
2016-12-19 20:57:39 -05:00
|
|
|
def gen():
|
|
|
|
try:
|
|
|
|
yield 123
|
|
|
|
except GeneratorExit:
|
|
|
|
print('GeneratorExit')
|
|
|
|
yield 456
|
|
|
|
|
2017-01-16 08:17:44 -05:00
|
|
|
# thrown a class
|
2016-12-19 20:57:39 -05:00
|
|
|
g = gen()
|
|
|
|
print(next(g))
|
2017-01-16 08:17:44 -05:00
|
|
|
print(g.throw(GeneratorExit))
|
|
|
|
|
|
|
|
# thrown an instance
|
|
|
|
g = gen()
|
|
|
|
print(next(g))
|
|
|
|
print(g.throw(GeneratorExit()))
|