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