Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting ipdb inside ipython breaks color coding (windows) #31

Labels

Comments

@asfaltboy
Copy link

Scenario:

  1. Run ipython (in windows), import and run a method that includes a call to ipdb (i just included import ipdb; ipdb.set_trace() inside a method that i imported in this case django's makemessages.py)
  2. Debugger starts but all the color coding is output as raw strings, like so:
> ←[1;32mc:\users\big\envs\appricot\lib\site-packages\django\core\management\commands\makemessages.py←[0m(184)←[0;36mprocess_file←
[1;34m()←[0m
←[1;32m    183 ←[1;33m        ←[1;32mimport←[0m ←[0mipdb←[0m←[1;33m;←[0m ←[0mipdb←[0m←[1;33m.←[0m←[0mset_trace←[0m←[1;33m(←[0m←[1;
33m)←[0m←[1;33m←[0m←[0m
←[0m←[1;32m--> 184 ←[1;33m        ←[0mthefile←[0m ←[1;33m=←[0m ←[0mfile←[0m←[1;33m←[0m←[0m
←[0m←[1;32m    185 ←[1;33m        ←[0morig_file←[0m ←[1;33m=←[0m ←[0mos←[0m←[1;33m.←[0m←[0mpath←[0m←[1;33m.←[0m←[0mjoin←[0m←[1;33m
(←[0m←[0mdirpath←[0m←[1;33m,←[0m ←[0mfile←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
←[0m
ipdb>

Edit: Just to clarify, my issue is reproducible on the first ipdb run, just by entering ipython and importing any module (sample.py) which includes the line import ipdb;ipdb.set_trace()

@rafaelolg
Copy link

Same here. Windows 7, Python 2.6.5, ipython 0.13 ipddb 0.7

The bug only happens when a second trace is activated after the first:

import ipdb;ipdb.set_trace()
import ipdb;ipdb.set_trace()

press 'c' for the first and then the bug happens.

@gotcha
Copy link
Owner

gotcha commented Sep 20, 2012

This issue is similar to what is told in the comments of #14.

I currently have no access to a Windows setup. I'll look at this as soon as I get access again.

@ernop
Copy link

ernop commented Sep 22, 2012

I think this might be related, too ipython/ipython#17 "redefining stdout in imported module breaks cmdprompt on windows"

@ernop
Copy link

ernop commented Sep 22, 2012

ok, the problem is caused by ipdb/main.py:44

commenting out that line solves the problem.

@tobinvanpelt
Copy link

can you provide more details on which line to comment out?

ipdb/main.py:44 is an "else" statement.

@tobinvanpelt
Copy link

OK ... I commented out line ipdb/main.py:43 which sets io.stdout and sys.stdout. Then I added a "pass" statement.

This now seems to work for me on windows.

@rafaelolg
Copy link

Yes it does, sorry for the wrong line number.

@apelliciari
Copy link

is it possible to include the fix in a release of ipdb?

@gotcha
Copy link
Owner

gotcha commented Mar 28, 2013

There is a comment on line 42 that states that 43 was done for nose.

Does one of you uses nose and can confirm that it still works on windows when line 43 is replaced by pass ?

@asfaltboy
Copy link
Author

Tested it on my Windows machine and it certainly fixes the issue

@gotcha
Copy link
Owner

gotcha commented Apr 22, 2013

@asfaltboy Sorry, to be picky, my question did not specify what to check with nose.
#8 describes what the problem with nose was. Is that what you checked ?

@asfaltboy
Copy link
Author

I checked the issue described here (#31) by running some code and breaking into ipdb and calling ipdb again (used a simple for loop). I'm not sure if this changes when run using another package that outputs to stdout (nose/unittest/etc..), but I'm inclined to believe it's not, since it's the same code in ipdb that's run.

@mikofski
Copy link

@rafaelolg Thanks for the fix. I had the problem under both scenarios (a) importing ipdb in Ipython or importing a module that contained an import of ipdb and (b) from the shell when running a python script that import ipdb twice. So happy to find this fix!

apelliciari pushed a commit to apelliciari/ipdb that referenced this issue Jan 19, 2014
@blink1073
Copy link

With this patch, I can run nosetests successfully and the prompt is not garbled when using IPython. I am using Python 2.7.7 Anaconda 2.0.1 (64-bit), Windows 7 with cb04b98.

diff --git a/ipdb/__main__.py b/ipdb/__main__.py
index 1618210..592892e 100644
--- a/ipdb/__main__.py
+++ b/ipdb/__main__.py
@@ -57,7 +57,8 @@ if IPython.__version__ > '0.10.2':

     def update_stdout():
         # setup stdout to ensure output is available with nose
-        io.stdout = sys.stdout = sys.__stdout__
+        if 'nose' in sys.modules.keys():
+            io.stdout = sys.stdout = sys.__stdout__
 else:
     from IPython.Debugger import Pdb, BdbQuit_excepthook
     from IPython.Shell import IPShell

@asfaltboy
Copy link
Author

@blink1073 I just want to make sure before closing the issue, have you tried running into ipdb continuing and in the same nose run entering ipdb again? If the colored output is not garbled in that case as well then the fix in master closes the issue.

@tobinvanpelt
Copy link

all good thanks

On Oct 15, 2014, at 4:44 AM, Pavel Savchenko notifications@github.com wrote:

@blink1073 I just want to make sure before closing the issue, have you tried running into ipdb continuing and in the same nose run entering ipdb again? If the colored output is not garbled in that case as well then the fix in master closes the issue.


Reply to this email directly or view it on GitHub.

@blink1073
Copy link

Did not work for me:

C:\Users\silvester\workspace>nosetests ipdb_test.py
> c:\users\silvester\workspace\ipdb_test.py(6)test_something()
      5     import ipdb; ipdb.set_trace()
----> 6     time.sleep(1)
      7     import ipdb; ipdb.set_trace()

ipdb> c
--Return--
None
> ←[1;32mc:\users\silvester\workspace\ipdb_test.py←[0m(6)←[0;36mtest_something←[
1;34m()←[0m
←[1;32m      5 ←[1;33m    ←[1;32mimport←[0m ←[0mipdb←[0m←[1;33m;←[0m ←[0mipdb←[0
m←[1;33m.←[0m←[0mset_trace←[0m←[1;33m(←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
←[0m←[1;32m----> 6 ←[1;33m    ←[0mtime←[0m←[1;33m.←[0m←[0msleep←[0m←[1;33m(←[0m←
[1;36m1←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
←[0m←[1;32m      7 ←[1;33m    ←[1;32mimport←[0m ←[0mipdb←[0m←[1;33m;←[0m ←[0mipd
b←[0m←[1;33m.←[0m←[0mset_trace←[0m←[1;33m(←[0m←[1;33m)←[0m←[1;33m←[0m←[0m
←[0m
ipdb> import ipdb
ipdb> ipdb.__path__
['c:\\users\\silvester\\workspace\\ipdb\\ipdb']
ipdb>
C:\Users\silvester\workspace\ipdb>git rev-parse HEAD
cb04b98897125de47bc02af1e1ffd12d6d3b4160

C:\Users\silvester\workspace\ipdb>

@gotcha
Copy link
Owner

gotcha commented Dec 22, 2014

Should be fixed by 9b2f0e5

@gotcha gotcha closed this as completed Dec 22, 2014
@blink1073
Copy link

Confirmed, thanks @gotcha!

@axil
Copy link

axil commented Jun 1, 2015

Works for me too, thanks!

@gotcha
Copy link
Owner

gotcha commented Jun 4, 2015

Released in https://pypi.python.org/pypi/ipdb/0.8.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment