[IPython-user] Problem with ipdb and generators...i think
Fernando Perez
fperez.net@gmail....
Mon Aug 27 11:42:33 CDT 2007
On 8/27/07, Tom Denniston <tom.denniston@alum.dartmouth.org> wrote:
> 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)
It seems to be a limitation at the pdb level, since I get the same
behavior in plain pdb as well:
planck[~/test]> python
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import genTest
>>> import pdb
>>> genTest.func1()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "genTest.py", line 2, in func1
func2().next().next()
File "genTest.py", line 6, in <genexpr>
yield (func3() for i in [1,2])
File "genTest.py", line 10, in func3
raise Exception('')
Exception
>>> pdb.pm()
> /home/fperez/test/genTest.py(10)func3()
-> raise Exception('')
(Pdb) l
5 while True:
6 yield (func3() for i in [1,2])
7
8
9 def func3():
10 -> raise Exception('')
[EOF]
(Pdb) u
> /home/fperez/test/genTest.py(6)<genexpr>()
-> yield (func3() for i in [1,2])
(Pdb) u
*** Oldest frame
(Pdb) 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('')
[EOF]
You may want to file a bug report on pdb itself...
Cheers,
f
More information about the IPython-user
mailing list