I am getting a really strange output when running a python script and setting a break point with ipdb as in this program:
import sys
import ipdb
parents, babies = (1, 1)
while babies < 100:
ipdb.set_trace()
print 'This generation has {0} babies'.format(babies)
ipdb.set_trace()
parents, babies = (babies, parents + babies)
It all works fine when running the script at first, stopping at the first break point and printing all the variables. But as soon as I approach the second break point where it doesn't matter if I step through it or just continue, I get these kind of weird characters as output in the console:
C:\pythontest>python ipdb_test2.py
> c:\pythontest\ipdb_test2.py(6)<module>()
5 ipdb.set_trace()
----> 6 print 'This generation has {0} babies'.format(babies)
7 ipdb.set_trace()
ipdb> n
This generation has 1 babies
> c:\pythontest\ipdb_test2.py(7)<module>()
6 print 'This generation has {0} babies'.format(babies)
----> 7 ipdb.set_trace()
8 parents, babies = (babies, parents + babies)
ipdb> n
> ←[1;32mc:\pythontest\ipdb_test2.py←[0m(8)←[0;36m<module>←[1;34m()←[0m
←[1;32m 6 ←[1;33m ←[1;32mprint←[0m ←[1;34m'This generation has {0} b
abies'←[0m←[1;33m.←[0m←[0mformat←[0m←[1;33m(←[0m←[0mbabies←[0m←[1;33m)←[0m←[1;33
m←[0m←[0m
←[0m←[1;32m 7 ←[1;33m ←[0mipdb←[0m←[1;33m.←[0m←[0mset_trace←[0m←[1;3
3m(←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
←[0m←[1;32m----> 8 ←[1;33m ←[0mparents←[0m←[1;33m,←[0m ←[0mbabies←[0m ←[1
;33m=←[0m ←[1;33m(←[0m←[0mbabies←[0m←[1;33m,←[0m ←[0mparents←[0m ←[1;33m+←[0m ←[
0mbabies←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
←[0m
ipdb> n
> ←[1;32mc:\pythontest\ipdb_test2.py←[0m(4)←[0;36m<module>←[1;34m()←[0m
←[1;32m 3 ←[1;33m←[0mparents←[0m←[1;33m,←[0m ←[0mbabies←[0m ←[1;33m=←[0m ←[
1;33m(←[0m←[1;36m1←[0m←[1;33m,←[0m ←[1;36m1←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
←[0m←[1;32m----> 4 ←[1;33m←[1;32mwhile←[0m ←[0mbabies←[0m ←[1;33m<←[0m ←[1;36m10
0←[0m←[1;33m:←[0m←[1;33m←[0m←[0m
←[0m←[1;32m 5 ←[1;33m ←[0mipdb←[0m←[1;33m.←[0m←[0mset_trace←[0m←[1;3
3m(←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
←[0m
ipdb>
As soon as I hit the ipdb.set_trace() command the second time it will output these kind of characters and from that point on the debugger becomes unusable. I tried it on different consoles but the error seems to persist.
I am using Python 2.7.8 with Anaconda 2.1.0 (64 bit) on Windows, any ideas how to solve this problem are warmly welcomed.
The strange output are ANSI escape codes. That's how ipdb does syntax highlighting. However CMD windows don't support the escape codes by default, it's been that way since DOS days. You have to enable a special driver named ANSI.SYS for the control codes to work. ipdb must be pulling some kind of magic that breaks the second time you call set_trace().