[IPython-user] Problem with ipdb and generators...i think

Tom Denniston tom.denniston@alum.dartmouth....
Mon Aug 27 11:24:03 CDT 2007


I have had some trouble with the inabilty to get full stack trace
movement when using generators in ipython pdb mode.  The problem is
often subtle because the generator evaluates at iteration time rather
than function call time which makes examples hard to follow.  I tried
to reproduce the problems with a simple example which is below.  The
problem, as I see it, is that ipdb can't seem to ascend the stack past
a generator even when the .next() call to the generator is nested
within function calls.  So, for instance, in the case below I would
expect following the error occurring in func 3 called by the generator
evaluted in func1, to be able to ascend from func 3 to generator (this
works), to func1 (this doesn't work).

Does this make sense to others?  Is it really a bug or am I missing
something?  It could be a bug in pdb or pydb but I don't exactly know
how to reproduce the way IPython is calling pydb to test this.  Code
and Ipython trace are below.

My IPython version is '0.7.4.svn.r2120'.


def func1():
	func2().next().next()

def func2():
	while True:
		yield (func3() for i in [1,2])


def func3():
	raise Exception('')


In [9]: genTest.func1()
---------------------------------------------------------------------------
<type 'exceptions.Exception'>             Traceback (most recent call last)

/src/<ipython console> in <module>()

/src/examples/genTest.py in func1()
----> 2         func2().next().next()
      3
      4 def func2():
      5         while True:
      6                 yield (func3() for i in [1,2])

/src/examples/genTest.py in <genexpr>((i,))
      4 def func2():
      5         while True:
----> 6                 yield (func3() for i in [1,2])
      7
      8

/src/examples/genTest.py in func3()
      6                 yield (func3() for i in [1,2])
      7
      8
      9 def func3():
---> 10         raise Exception('')
<type 'exceptions.Exception'>:
(/src/examples/genTest.py:10):  func3
(Pydb) u
(/src/examples/genTest.py:6):  <genexpr>
(Pydb) u
*** Adjusting would be put us beyond the oldest frame
(Pydb) l
      1 def func1():
      2         func2().next().next()
      3
      4 def func2():
      5         while True:
----> 6                 yield (func3() for i in [1,2])
      7
      8
      9 def func3():
     10         raise Exception('')
(Pydb)


More information about the IPython-user mailing list