import pdb def gen(): for i in range(2): if i == 1: 1 / 0 line_number = 7 yield i def foo(): it = gen() next(it) next(it) pdb.Pdb().set_trace() foo()