Giter Site home page Giter Site logo

ipdb's Introduction

IPython pdb

https://codecov.io/gh/gotcha/ipdb/branch/master/graphs/badge.svg?style=flat

Use

ipdb exports functions to access the IPython debugger, which features tab completion, syntax highlighting, better tracebacks, better introspection with the same interface as the pdb module.

Example usage:

import ipdb
ipdb.set_trace()
ipdb.set_trace(context=5)  # will show five lines of code
                           # instead of the default three lines
                           # or you can set it via IPDB_CONTEXT_SIZE env variable
                           # or setup.cfg file
ipdb.pm()
ipdb.run('x[0] = 3')
result = ipdb.runcall(function, arg0, arg1, kwarg='foo')
result = ipdb.runeval('f(1,2) - 3')

Arguments for set_trace

The set_trace function accepts context which will show as many lines of code as defined, and cond, which accepts boolean values (such as abc == 17) and will start ipdb's interface whenever cond equals to True.

Using configuration file

It's possible to set up context using a .ipdb file on your home folder, setup.cfg or pyproject.toml on your project folder. You can also set your file location via env var $IPDB_CONFIG. Your environment variable has priority over the home configuration file, which in turn has priority over the setup config file. Currently, only context setting is available.

A valid setup.cfg is as follows

[ipdb]
context=5

A valid .ipdb is as follows

context=5

A valid pyproject.toml is as follows

[tool.ipdb]
context=5

The post-mortem function, ipdb.pm(), is equivalent to the magic function %debug.

If you install ipdb with a tool which supports setuptools entry points, an ipdb script is made for you. You can use it to debug your python 2 scripts like

$ bin/ipdb mymodule.py

And for python 3

$ bin/ipdb3 mymodule.py

Alternatively with Python 2.7 only, you can also use

$ python -m ipdb mymodule.py

You can also enclose code with the with statement to launch ipdb if an exception is raised:

from ipdb import launch_ipdb_on_exception

with launch_ipdb_on_exception():
    [...]

Warning

Context managers were introduced in Python 2.5. Adding a context manager implies dropping Python 2.4 support. Use ipdb==0.6 with 2.4.

Or you can use iex as a function decorator to launch ipdb if an exception is raised:

from ipdb import iex

@iex
def main():
    [...]

Warning

Using from future import print_function for Python 3 compat implies dropping Python 2.5 support. Use ipdb<=0.8 with 2.5.

Issues with stdout

Some tools, like nose fiddle with stdout.

Until ipdb==0.9.4, we tried to guess when we should also fiddle with stdout to support those tools. However, all strategies tried until 0.9.4 have proven brittle.

If you use nose or another tool that fiddles with stdout, you should explicitly ask for stdout fiddling by using ipdb like this

import ipdb
ipdb.sset_trace()
ipdb.spm()

from ipdb import slaunch_ipdb_on_exception
with slaunch_ipdb_on_exception():
    [...]

Development

ipdb source code and tracker are at https://github.com/gotcha/ipdb.

Pull requests should take care of updating the changelog HISTORY.txt.

Under the unreleased section, add your changes and your username.

Manual testing

To test your changes, make use of manual_test.py. Create a virtual environment, install IPython and run python manual_test.py and check if your changes are in effect. If possible, create automated tests for better behaviour control.

Automated testing

To run automated tests locally, create a virtual environment, install coverage and run coverage run setup.py test.

Third-party support

Products.PDBDebugMode

Zope2 Products.PDBDebugMode uses ipdb, if available, in place of pdb.

iw.debug

iw.debug allows you to trigger an ipdb debugger on any published object of a Zope2 application.

ipdbplugin

ipdbplugin is a nose test runner plugin that also uses the IPython debugger instead of pdb. (It does not depend on ipdb anymore).

pytest

pytest supports a --pdb option which can run ipdb / IPython.terminal.debugger:Pdb on Exception and breakpoint():

pytest --pdb --pdbcls=IPython.terminal.debugger:Pdb -v ./test_example.py

You don't need to specify --pdbcls for every pytest invocation if you add addopts to pytest.ini or pyproject.toml.

pytest.ini:

[tool.pytest.ini_options]
addopts = "--pdbcls=IPython.terminal.debugger:Pdb"

pyproject.toml:

[tool.pytest.ini_options]
addopts = "--pdbcls=IPython.terminal.debugger:Pdb"

ipdb's People

Contributors

adamchainz avatar alanbernstein avatar alexandrebarbaruiva avatar andreagrandi avatar andrewzwicky avatar bjornfjohansson avatar bmw avatar cpcloud avatar d1618033 avatar dimasad avatar gnebehay avatar gotcha avatar ixday avatar jbkahn avatar kynan avatar lebedov avatar mrmino avatar msabramo avatar native-api avatar nphilipp avatar omergertel avatar osyvokon avatar pidelport avatar psycojoker avatar salty-horse avatar sas23 avatar steinnes avatar takluyver avatar vphilippon avatar zvodd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ipdb's Issues

Importing ipdb in ipython startup files breaks tab completion.

I don't know exactly why yet, but importing ipdb in IPython startup files (i.e. ~/.ipython./profile_default/startup/) breaks tab completion.

The issue has to do with line 32 in ipdb/__main__.py which tests for the global symbol get_ipython. At this early state of startup, the global symbol is not defined, and then something in the except NameError: block breaks the completer. (Somehow the completer that can actually do completions is replaced with another broken completer. Probably due to the embedding.)

Is there a more robust way of doing this test that will also work in the startup files?

ipdb ignores my ipython color scheme

My ~/.config/ipython/profile_default/ipython_config.py contains c.TerminalInteractiveShell.colors = 'LightBG'. ipython honors that. ipdb doesn't, and I get to enjoy text displayed in light yellow on white background in my tracebacks.

Looks like bug #1 is back?

I've got ipdb 0.8 and ipython 1.2.0.

I'm invoking ipdb by inserting import ipdb; ipdb.set_trace() in my application code.

History across different ipdb sessions?

Is it possible to save history across different ipdb sessions? I would like pull up commands from my previous ipdb debug session that was invoked using ipdb.set_trace().

Print whole exception

When I use "n" to step past code and there's an exception, the exception gets truncated like so:
"ValidationError: Validati...ists.']})"

Is there any way to configure ipdb to print the whole exception? Is there a command to quickly access the last raised exception?

Missing syntax highlighting on longlist

list prints the nearby sourcecode along with syntax highlighting.

longlist prints the sourcecode for the entire function/method, but omits syntax highlighting.

longlist should have the same syntax highlighting as list.

'import ipdb' fails on Python 2.5

Just upgraded to ipdb 0.6 (from version 0.3) on Python 2.5, and now it will not import.

$ python -c "import ipdb"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/jcross/utils/release-tools/__init__.py", line 1, in <module>

  File "build/bdist.linux-i686/egg/ipdb/__main__.py", line 14, in <module>
ImportError: No module named core.debugger

$ python -m ipdb
Traceback (most recent call last):
  File "/usr/lib/python2.5/runpy.py", line 95, in run_module
    filename, loader, alter_sys)
  File "/usr/lib/python2.5/runpy.py", line 52, in _run_module_code
    mod_name, mod_fname, mod_loader)
  File "/usr/lib/python2.5/runpy.py", line 32, in _run_code
    exec code in run_globals
  File "/home/jcross/utils/release-tools/__init__.py", line 1, in <module>

ImportError: cannot import name set_trace

ipdb got stuck with copy

Hi, I meet the following problem:

import ipdb

def a():
ipdb.trac()
print "A"

a()

AttributeError Traceback (most recent call last)
C:\Users\Jasper\Desktop in ()
----> 1 a()

C:\Users\Jasper\Desktop in a()
1 def a():
----> 2 ipdb.trac()
3 print "A"
4

AttributeError: 'module' object has no attribute 'trac'

%debug

(2)a()
1 def a():
----> 2 ipdb.trac()
3 print "A"

I select "print "A"", right click, select "Copy", and press Ctrl+V to paste in the following place:
ipdb> print "A"

Then strangely, whatever I type and hit ENTER, there is no reaction! I cannot exit by input q.

Allow configuration of ipdb context

In order to greatly improve usability, the debugger should be able to be configured to display more lines of context. The current default of 3 lines makes it difficult to know where you are in the code.

A 'fullscreen' option that fills the terminal window would be nice as well and would behave a lot more like a visual debuggers.

ipython 1.0 deprecation warning

U should change from

    from IPython.frontend.terminal.embed import InteractiveShellEmbed

    from IPython.terminal.embed import InteractiveShellEmbed

to get rid of the deprecation warning for ipython 1.0.

beginner question

I just installed ipdb and I get weird output like this, what am I doing wrong?

I'm on Win 7, Python 2.6 running in a bash shell. IPython itself works fine though.

โ†[1;32m 12 โ†[1;33m โ†[1;32mimportโ†[0m โ†[1;37mipdbโ†[0mโ†[1;33m;โ†[0m โ†[1;37mipdbโ†[0mโ†[1;33m.โ†[0mโ†[1;37mset_traceโ†[0mโ†[1;33m(โ†[0mโ†[1;33m)โ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0mโ†[1;32m---> 13 โ†[1;33m โ†[1;37msuperโ†[0mโ†[1;33m(โ†[0mโ†[1;37mCheckoutAppโ†[0mโ†[1;33m,โ†[0m โ†[1;37mselfโ†[0mโ†[1;33m)โ†[0mโ†[1;33m.โ†[0mโ†[1;37mprepare_orderโ†[0mโ†[1;33m(โ†[0mโ†[1;37mrequestโ†[0mโ†[1;33m)โ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0mโ†[1;32m 14 โ†[1;33mโ†[1;33mโ†[0mโ†[0m โ†[0m ipdb> p self.order_model <class 'satchless.order.models.Order'> ipdb> l โ†[0;32m 8 โ†[0m โ†[1;37mcart_modelโ†[0m โ†[1;33m=โ†[0m โ†[1;37mcart_modelsโ†[0mโ†[1;33m.โ†[0mโ†[1;37mCartโ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0;32m 9 โ†[0m โ†[1;37morder_modelโ†[0m โ†[1;33m=โ†[0m โ†[1;37morder_modelsโ†[0mโ†[1;33m.โ†[0mโ†[1;37mOrderโ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0;32m 10 โ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0;32m 11 โ†[0m โ†[1;32mdefโ†[0m โ†[1;37mprepare_orderโ†[0mโ†[1;33m(โ†[0mโ†[1;37mselfโ†[0mโ†[1;33m,โ†[0m โ†[1;37mrequestโ†[0mโ†[1;33m)โ†[0mโ†[1;33m:โ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0;32m 12 โ†[0m โ†[1;32mimportโ†[0m โ†[1;37mipdbโ†[0mโ†[1;33m;โ†[0m โ†[1;37mipdbโ†[0mโ†[1;33m.โ†[0mโ†[1;37mset_traceโ†[0mโ†[1;33m(โ†[0mโ†[1;33m)โ†[0mโ†[1;33mโ†[0mโ†[0m โ†[1;32m---> 13 โ†[1;33m โ†[1;37msuperโ†[0mโ†[1;33m(โ†[0mโ†[1;37mCheckoutAppโ†[0mโ†[1;33m,โ†[0m โ†[1;37mselfโ†[0mโ†[1;33m)โ†[0mโ†[1;33m.โ†[0mโ†[1;37mprepare_orderโ†[0mโ†[1;33m(โ†[0mโ†[1;37mrequestโ†[0mโ†[1;33m)โ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0mโ†[0;32m 14 โ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0;32m 15 โ†[0mโ†[1;33mโ†[0mโ†[0m โ†[0;32m 16 โ†[0mโ†[1;37mcheckout_appโ†[0m โ†[1;33m=โ†[0m โ†[1;37mCheckoutAppโ†[0mโ†[1;33m(โ†[0mโ†[1;33m)โ†[0mโ†[1;33mโ†[0mโ†[0m

Ipython magic functions

Is it possible to use ipython magic functions inside ipdb ?
If yes, please give a small example.

access to magic functions?

Magic functions don't seem to work from the ipdb prompt, although they are visible in the tab completion.

ipdb>  %prun some_function()
*** SyntaxError: invalid syntax (<stdin>, line 1)

IPython 'crash report' spam on exception

Consider the following code:

import ipdb;ipdb.set_trace()
1/0

Executing this code, then typing 'continue' into ipdb, should generate a traceback of the form:

Traceback (most recent call last):
  File "zero.py", line 2, in <module>
    1/0
ZeroDivisionError: integer division or modulo by zero

Instead, it generates a (considerably harder to read) IPython crash report:

ZeroDivisionError                            Python 2.7.1+: /usr/bin/python
                                                   Fri Oct 14 11:26:18 2011
A problem occured executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.

/home/jcross/zero.py in <module>()
      1 
----> 2 
      3 
      4 
      5 
      6 
      7 
      8 
      9 
     10 
     11 
     12 
     13 
     14 
     15 import ipdb;ipdb.set_trace()
     16 1/0
     17 
     18 
     19 
     20 
     21 
     22 
     23 
     24 
     25 
     26 
     27 
     28 
     29 
     30 
     31 

ZeroDivisionError: integer division or modulo by zero

**********************************************************************

Oops, IPython crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the crash traceback.
  - A copy of your input history during this session.
  - Data on your current IPython configuration.

It was left in the file named:
    '/home/jcross/.ipython/IPython_crash_report.txt'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to: Fernando Perez at [email protected]
with the subject 'IPython Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s 'IPython Crash Report' [email protected] < /home/jcross/.ipython/IPython_crash_report.txt

To ensure accurate tracking of this issue, please file a report about it at:
https://bugs.launchpad.net/ipython/+filebug

Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/IPython/Debugger.py", line 66, in BdbQuit_excepthook
    BdbQuit_excepthook.excepthook_ori(et,ev,tb)
  File "/usr/lib/python2.7/dist-packages/IPython/CrashHandler.py", line 157, in __call__
    report.write(self.make_report(traceback))
  File "/usr/lib/python2.7/dist-packages/IPython/CrashHandler.py", line 215, in make_report
    rpt_add('BZR revision   : %s \n\n' % Release.revision)
AttributeError: 'module' object has no attribute 'revision'

Original exception was:
Traceback (most recent call last):
  File "zero.py", line 2, in <module>
    1/0
ZeroDivisionError: integer division or modulo by zero

Using Python 2.7, IPython 0.10.1 and ipdb 0.6.

How to use ipdb.pm() inside except clause?

My web app code looks sort of like this:

try:
    # handle the request
except Exception as ex:

    # pdb.post_mortem() # this is what I used to use

    ipdb.pm() # trying out ipdb instead

With the old pdb module, when my web code blew up, in the terminal where I launched the web app, I would have a pdb session open.

But with ipdb, I get this traceback:

Traceback (most recent call last):
  File "/home/matt/.virtualenvs/ddsreminder/lib/python2.7/site-packages/gunicorn-0.14.1 py2.7.egg/gunicorn/workers/sync.py", line 99, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/home/matt/checkouts/ddsreminder/src/ddsreminder/webapp/dispatcher.py", line 96, in __call__
    ipdb.pm()
  File "build/bdist.linux-i686/egg/ipdb/__main__.py", line 70, in pm
    post_mortem(sys.last_traceback)
AttributeError: 'module' object has no attribute 'last_traceback'

What am I doing wrong here?

Python 3.4.2 installation error

Trying to install ipdb inside a virtualenv with Python 3.4.2 on a linux box.

Running python setup.py install and pip install ipdb same result.

running install
Traceback (most recent call last):
  File "setup.py", line 59, in <module>
    use_2to3=True,
  File "/home/wiliam/.pyenv/versions/3.4.2/lib/python3.4/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/home/wiliam/.pyenv/versions/3.4.2/lib/python3.4/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/home/wiliam/.pyenv/versions/3.4.2/lib/python3.4/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/wiliam/.virtualenvs/test/lib/python3.4/site-packages/setuptools/command/install.py", line 67, in run
    self.do_egg_install()
  File "/home/wiliam/.virtualenvs/test/lib/python3.4/site-packages/setuptools/command/install.py", line 103, in do_egg_install
    cmd.ensure_finalized()  # finalize before bdist_egg munges install cmd
  File "/home/wiliam/.pyenv/versions/3.4.2/lib/python3.4/distutils/cmd.py", line 107, in ensure_finalized
    self.finalize_options()
  File "/home/wiliam/.virtualenvs/test/lib/python3.4/site-packages/setuptools/command/easy_install.py", line 283, in finalize_options
    'install_lib', ('install_dir', 'install_dir')
  File "/home/wiliam/.pyenv/versions/3.4.2/lib/python3.4/distutils/cmd.py", line 287, in set_undefined_options
    src_cmd_obj.ensure_finalized()
  File "/home/wiliam/.pyenv/versions/3.4.2/lib/python3.4/distutils/cmd.py", line 107, in ensure_finalized
    self.finalize_options()
  File "/home/wiliam/.virtualenvs/test/lib/python3.4/site-packages/setuptools/command/install_lib.py", line 16, in finalize_options
    self.set_undefined_options('install',('install_layout','install_layout'))
  File "/home/wiliam/.pyenv/versions/3.4.2/lib/python3.4/distutils/cmd.py", line 290, in set_undefined_options
    setattr(self, dst_option, getattr(src_cmd_obj, src_option))
  File "/home/wiliam/.pyenv/versions/3.4.2/lib/python3.4/distutils/cmd.py", line 103, in __getattr__
    raise AttributeError(attr)
AttributeError: install_layout

Starting ipdb inside ipython breaks color coding (windows)

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()

pdef, pdoc, pinfo always return "Object `X` not found"

Apologies if I am using them incorrectly, but these interfaces to the magic_pxx commands never seem to work for me, regardless of object.

ipdb> master
<Node: master (i-2908d24c)>
ipdb> type(master)
<class 'starcluster.node.Node'>
ipdb> pdef master
Object `master` not found.
ipdb> pdoc master
Object `master` not found.
ipdb> pinfo master
Object `master` not found.

Same if I create an object within ipdb:

ipdb> import numpy
ipdb> A = numpy.array([3, 3])
ipdb> A
array([3, 3])
ipdb> pinfo A
Object `A` not found.

I'm using Ipython 0.12 and ipdb 0.6.1.

Output not visible inside IPython notebook

When ipdb.set_trace() is called, it calls this function:

def update_stdout():
    # setup stdout to ensure output is available with nose
    io.stdout = sys.stdout = sys.__stdout__

This results in output being written back to the terminal where the notebook was launched, instead of appearing in the notebook itself. It will do the wrong thing in any context where you want the output to be redirected. Commenting out the call to this function makes it behave as expected.

I'm not sure what's the right heuristic to guess whether output should be redirected or not.

Reported as ipython/ipython#5247.

sqlite exceptions on exit if I use ipdb in a multi-threaded app

  1. Start a multi-threaded app (ZTK-based in my case, but I don't think it matters)
  2. Insert an ipdb breakpoint in some view
  3. Try to render that view
  4. Press either ^C or ^D (assuming Linux) on the console at the ipdb prompt

What happens: BdbQuit is raised which terminates the debugging session but then I also get the following spew:

BdbQuit
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3115, in atexit_operations
    self.history_manager.end_session()
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.py", line 504, in end_session
    self.writeout_cache()
  File "<string>", line 2, in writeout_cache
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.py", line 65, in needs_sqlite
    return f(self, *a, **kw)
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.py", line 680, in writeout_cache
    self._writeout_input_cache(conn)
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.py", line 664, in _writeout_input_cache
    (self.session_number,)+line)
ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 47876379322112 and this is thread id 47876201294400
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python2.7/atexit.py", line 24, in _run_exitfuncs
    func(*targs, **kargs)
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3115, in atexit_operations
    self.history_manager.end_session()
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.py", line 504, in end_session
    self.writeout_cache()
  File "<string>", line 2, in writeout_cache
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.py", line 65, in needs_sqlite
    return f(self, *a, **kw)
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.py", line 680, in writeout_cache
    self._writeout_input_cache(conn)
  File "/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.py", line 664, in _writeout_input_cache
    (self.session_number,)+line)
ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 47876379322112 and this is thread id 47876201294400
Error in sys.exitfunc:
---------------------------------------------------------------------------
ProgrammingError                          Traceback (most recent call last)
/usr/lib/python2.7/atexit.pyc in _run_exitfuncs()
     22         func, targs, kargs = _exithandlers.pop()
     23         try:
---> 24             func(*targs, **kargs)
     25         except SystemExit:
     26             exc_info = sys.exc_info()

/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in atexit_operations(self)
   3113         # this must be *before* the tempfile cleanup, in case of temporary
   3114         # history db
-> 3115         self.history_manager.end_session()
   3116 
   3117         # Cleanup all tempfiles left around

/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.pyc in end_session(self)
    502     def end_session(self):
    503         """Close the database session, filling in the end time and line count."""
--> 504         self.writeout_cache()
    505         with self.db:
    506             self.db.execute("""UPDATE sessions SET end=?, num_cmds=? WHERE

/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.pyc in writeout_cache(self, conn)

/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.pyc in needs_sqlite(f, self, *a, **kw)
     63         return []
     64     else:
---> 65         return f(self, *a, **kw)
     66 
     67 

/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.pyc in writeout_cache(self, conn)
    678         with self.db_input_cache_lock:
    679             try:
--> 680                 self._writeout_input_cache(conn)
    681             except sqlite3.IntegrityError:
    682                 self.new_session(conn)

/path/to/my/virtualenv/lib/python2.7/site-packages/IPython/core/history.pyc in _writeout_input_cache(self, conn)
    662             for line in self.db_input_cache:
    663                 conn.execute("INSERT INTO history VALUES (?, ?, ?, ?)",
--> 664                                 (self.session_number,)+line)
    665 
    666     def _writeout_output_cache(self, conn):

ProgrammingError: SQLite objects created in a thread can only be used in that same thread.The object was created in thread id 47876379322112 and this is thread id 47876201294400

Maybe it's an IPython bug; I don't know which piece of code is responsible for registering those atexit handlers.

watchpoint

Hi,
is it planned to add watchpoints to ipdb?

It would be nice enhancement!

Thanks

Ondra

Unable to run/restart ipdb

I'm not having any luck using the 'run' command inside ipdb. Typing run or restart from the ipdb prompt gives me the following stack-trace:

ipdb> restart

NameError Traceback (most recent call last)
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.pyc in run_module(mod_name, init_globals, run_name, alter_sys)
174 if alter_sys:
175 return _run_module_code(code, init_globals, run_name,
--> 176 fname, loader, pkg_name)
177 else:
178 # Leave the sys module alone

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.pyc in _run_module_code(code, init_globals, mod_name, mod_fname, mod_loader, pkg_name)
80 mod_globals = temp_module.module.dict
81 _run_code(code, mod_globals, init_globals,
---> 82 mod_name, mod_fname, mod_loader, pkg_name)
83 # Copy the globals of the temporary module, as they
84 # may be cleared when the temporary module goes away

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.pyc in _run_code(code, run_globals, init_globals, mod_name, mod_fname, mod_loader, pkg_name)
70 loader = mod_loader,
71 package = pkg_name)
---> 72 exec code in run_globals
73 return run_globals
74

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipdb/main.py in ()
157
158 if name == 'main':
--> 159 main()

/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/ipdb/main.py in main()
140 break
141 print "The program finished and will be restarted"
--> 142 except Restart:
143 print "Restarting", mainpyfile, "with arguments:"
144 print "\t" + " ".join(sys.argv[1:])

NameError: global name 'Restart' is not defined
WARNING: Unknown failure executing module:

When using pdb, however, I don't have any problems. Thus, it's not the pdb package.

ipdb fails to ascend above current frame when mixing iterators and context managers

The following code reproduces the issue:

import sys
from contextlib import contextmanager


def f():
    for x in iterator():
        pass

def iterator():
    with ctx():
        yield
    raise Exception()

@contextmanager
def ctx():
    yield


if __name__ == "__main__":
    try:
        f()
    except:
        import ipdb
        ipdb.post_mortem(sys.exc_info()[2])

When entering ipdb in the above example one cannot go up above iterator, i.e. to f(). Replacing ipdb with pdb works...

continue until reaching your own code

I use ipdb for debugging Django & I'll often call a deep system or django function, which will generate a deep stack, at the bottom of which it's calling one of my own functions (but I'm not sure which).

In order to figure it out, I usually set a breakpoint right before the call, and then step down into it about 10 times, to get to where it calls my own function. In django this comes up a lot because it has lots of functions which are just two lines, something like:

if False:
xyz
return self.inner_function()

and these are pretty annoying to step through to get back to my own code.

I was thinking, it'd be pretty great to be able to define a target directory and then be able to issue a different type of continue command from within ipdb, which would do a normal continue, but automatically stop whenever execution returned to a file in or below the target directory you had defined.

This would make it so that I could just do "ct" before system calls, and it'd continue until it returned to my own code. In some ways it'd be like the "next" command - if there were only system calls contained in your function. But if there were hidden calls to your own code, you'd automatically stop there.

Really, it could be implemented with smart aliases - just keep stepping until the currently executing frame matches the target dir - but doing it there would probably be slow.

I realize that this could also be done by just setting breakpoints at the start of all my functions, or by logging all my functions. This would work in some cases, but if I don't want to always break there, then it would require setting up lots of ignored breakpoints and having them trigger at the right time - it could get complicated.

Anyway, is this something that exists already?

WARNING: IPython History requires SQLite, your history will not be saved

With current Plone 4.2.2, I'm getting ipdb as a dependency of iw.debug. When starting a debug instance, the last output line before the prompt appears is:

WARNING: IPython History requires SQLite, your history will not be saved

I installed pysqlite in the virtualenv, but the issue persists. How does IPython expect to find sqlite?

Ubuntu 10.10, installed packages:

ii  libsqlite0     2.8.17-6build2 SQLite shared library
ii  libsqlite0-dev 2.8.17-6build2 SQLite development files
ii  libsqlite3-0   3.7.2-1ubuntu0 SQLite 3 shared library
ii  libsqlite3-dev 3.7.2-1ubuntu0 SQLite 3 development files

Also, after the first error, app (the Zope app instance) becomes undefined. I don't know if this is related.

licensing issues

any chance license will ever be changed to something less restrictive like MIT or similar?

AttributeError with old ipython

I wouldn't open a bug triggered by an old checkout of iPython, but then I saw that the code integrates some efforts to support several of them, so...

I am using a git checkout of iPython from May (simply because I never installed a newer version of Tornado), and importing ipdb results in

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-1-2d6f026194dd> in <module>()
----> 1 import ipdb

/home/nobackup/repo/ipdb/ipdb/__init__.py in <module>()
     14 # You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.>
     15 
---> 16 from ipdb.__main__ import set_trace, post_mortem, pm, run, runcall, runeval, launch_ipdb_on_exception
     17 
     18 pm                       # please pyflakes

/home/nobackup/repo/ipdb/ipdb/__main__.py in <module>()
     52         def_colors = ipshell.colors
     53     else:
---> 54         def_colors = get_ipython.im_self.colors
     55 
     56     from IPython.utils import io

AttributeError: 'function' object has no attribute 'im_self'

I ignore if this happens with some official release, but I'm submitting a fix.

import ipdb results in bytes output to the stdout.

test.py

#!/usr/bin/env python
import ipdb

Running:

$ ./test.py 1>| ipdb.txt
$ wc --bytes ipdb.txt 
8 mm.txt

File is 8 bytes.

Out[7]: ['\x1b', '[', '?', '1', '0', '3', '4', 'h']
$ hexdump ipdb.txt 
0000000 5b1b 313f 3330 6834                    
0000008

I'm on ipdb 0.8.

Can't see the output of ipdd==0.8.1 when used with behave==1.2.5

Hi All,

After upgrading ipdb to v0.8.1 and behave to v1.2.5, ipdb stopped working properly.
Basically when execution stops at the breakpoint, and you issue any of the ipdb commands then you won't see the output of that command.
Here's an example repo that you can use to reproduce the issue: https://github.com/kowalcj0/behaveipdb

btw. I wasn't able to tell whether it's an issue with ipdb or behave so I've reported it on both projects' github repos.

post_mortem displays wrong line in traceback with contextmanager

When entering post_mortem from a contextmanager, the wrong line is printed in the traceback. This is different than what happens with pdb and even IPython.core.debugger.

Here is a short example, with a TypeError in line 15:

import ipdb
from contextlib import contextmanager

@contextmanager
def ctxmanager(a):
    a = 1
    yield a
    e = 5

def main():
 with ipdb.launch_ipdb_on_exception():
    a = 1
    with ctxmanager(a) as abc:
            a = 2
            b = id*3
            c = 43

if __name__=='__main__':
    main()

Here's the output:

     15             b = id*3
---> 16             c = 43
     17 

Here's the expected output:

     14             a = 2
---> 15             b = id*3
     16             c = 43

To solve, need to start the interaction without passing the frame (frame lines and traceback lines don't match, because of the contextmanager moving to the exit). Without the frame, pdb uses the expected line number. This is closer to the post_mortem of pdb.

def post_mortem(tb):
    update_stdout()
    wrap_sys_excepthook()
    p = Pdb(def_colors)
    p.reset()
    if tb is None:
        return
    p.interaction(None, tb)

Tried with Python2.7 and latest IPython and default pdb.

TerminalIPythonApp.exec_lines doesn't seems to have any effect

It's handy to setup ~/.config/ipython/profile_default/ipython_config.py to autoload modules in the ipython shell :

c.TerminalIPythonApp.exec_lines = [
'import os, sys, re, json'
]

This way the shell experience is much smoother, most used actions are available at the fingertips.

But it doesn't work when we do:

import ipdb; ipdb.set_trace()

Which would be even handier, cause in debug you always need stuff such as datetime, json and such and it's a pain to import them all at every run.

Ipdb fails with the latest development version of IPython

I have installed the latest development version of ipython
(commit c6d6492230477224ee7e61bfee8741de58e28482)

in the Anaconda python distribution, version 1.6, on Mac Os X.

The Ipdb now fails to work (use the standard import ipdb; ipdb.set_trace())
with the following error:
Traceback (most recent call last):
File "t1.py", line 5, in
fnam = cum.cor_fun(u'../../smesi-plot/ะกะผะตััŒ9-120-ะด.SIN')
File "/Users/ivan/work/reports/kand-2011/etap-5/nano/cum.py", line 63, in init
import ipdb; ipdb.set_trace()
File "/Users/ivan/anaconda/lib/python2.7/site-packages/ipdb-0.7-py2.7.egg/ipdb/init.py", line 16, in
from ipdb.main import set_trace, post_mortem, pm, run, runcall, runeval, launch_ipdb_on_exception
File "/Users/ivan/anaconda/lib/python2.7/site-packages/ipdb-0.7-py2.7.egg/ipdb/main.py", line 34, in
ipshell = InteractiveShellEmbed()
File "/Users/ivan/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/embed.py", line 97, in init
display_banner=display_banner
File "/Users/ivan/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 360, in init
user_module=user_module, custom_exceptions=custom_exceptions
File "/Users/ivan/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 498, in init
self.init_magics()
File "/Users/ivan/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/embed.py", line 112, in init_magics
super(InteractiveShellEmbed, self).init_magics()
File "/Users/ivan/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 719, in init_magics
self.register_magics(TerminalMagics)
File "/Users/ivan/anaconda/lib/python2.7/site-packages/IPython/core/magic.py", line 389, in register
m = m(shell=self.shell)
File "/Users/ivan/anaconda/lib/python2.7/site-packages/IPython/frontend/terminal/interactiveshell.py", line 84, in init
self.input_splitter = IPythonInputSplitter(input_mode='line')

Support -m flag

So one can run the equivalent of e.g. python -m alembic.config revision --autogenerate

Cannot import ipdb in usercustomize.py

usercustomize.py (http://docs.python.org/2/tutorial/interpreter.html#the-customization-modules) allows one to run custom code anytime the Python VM starts.

It can be useful to make default import.

E.G, on my local machine, I have have set_trace() from pdb imported in it, this allow me to just write set_trace() to add a break point.

Now the trick is that this script is run very early, and some things are not available, such as builtin and sys.argv.

In my usercutomize.py, I have to do this:

import __builtin__

from pdb import set_trace

__builtin__.set_trace = set_trace

Now, if you try to do something like this with ipdb (on a conditional import of course) it fails here:

  File "/usr/lib/python2.7/dist-packages/IPython/config/application.py", line 67, in <module>
    """.strip().format(app=os.path.basename(sys.argv[0]))
AttributeError: 'module' object has no attribute 'argv'

It sucks because things like launch_ipdb_on_exception are not interesting at all if there are not already imported as it's faster to just try/except than to write the import then the with clause.

Now since it's not ipdb in cause, but iPython, I don't know if you can fix it, but maybe you can hack something (injecting temporarly sys.argv, mocking sys just for ipython if sys doesn't exists and putting it back... I know it's ugly :-)) or try to get in touch with the ipython guy and solve that together.

Expose Pdb API

It would be nice if ipdb exposed some kind of API, like pdb.Pdb and IPython.core.debugger.PDB. This would make it much easier to extend existing code that uses pdb, to use ipdb instead, without needing to rewrite the existing code.

NameError when using a generator

After calling ipdb.set_trace()

ipdb> y = 4
ipdb> x = list(y for i in [1])
*** NameError: global name 'y' is not defined

This code works as expected in pdb in a regular python shell.

Bug shows in released versions ipython version 0.12 and ipdb 0.6.1 and also latest git HEAD for both projects:

ipdb 4ff7999 2012-02-28
ipython 96d5447cf90f 2012-03-06

python -m ipdb

I can start pdb this way:

python -m pdb manage.py test tests

But with ipdb this does not work:

python -m ipdb manage.py test tests     
python: No module named ipdb.__main__; 'ipdb' is a package and cannot be directly executed

No output inside nose tests

When I insert an "import ipdb;ipdb.set_trace()" inside a nose test case, running of the tests pauses but nothing is output on the terminal.

I've made a patch to fix this in my fork of ipdb in February 2010: see akaihola/ipdb@0894324

Unfortunately my repository isn't a fork of yours. IIRC I created it by cloning svn.gotcha.python-hosting.com since there were no GitHub mirrors at that time.

a debugged program crashes ipdb

Hi!

Thank you for doing a great job!
I have an issue with ipdb, it crashes after the debugged program crashes. I am not sure, however, that the issue in ipdb.
The operating system is Ubuntu 11.04, iPython's version is 2.7.1.

Please see the log:

bezalel-laptop:~$ cat /tmp/test.py
a = 1
b = 0
print a/b

bezalel-laptop:~$ python -m ipdb /tmp/test.py
> /tmp/test.py(1)<module>()
----> 1 a = 1
      2 b = 0
      3 print a/b

ipdb> c
---------------------------------------------------------------------------
NameError                                    Python 2.7.1+: /usr/bin/python
                                                   Wed Jul 13 16:38:38 2011
A problem occured executing Python code.  Here is the sequence of function
calls leading up to the error, with the most recent (innermost) call last.

/usr/lib/python2.7/runpy.pyc in _run_module_as_main(mod_name='ipdb.__main__', alter_argv=1)
    147            __package__
    148     """
    149     try:
    150         if alter_argv or mod_name != "__main__": # i.e. -m switch
    151             mod_name, loader, code, fname = _get_module_details(mod_name)
    152         else:          # i.e. directory or zipfile execution
    153             mod_name, loader, code, fname = _get_main_module_details()
    154     except ImportError as exc:
    155         msg = "%s: %s" % (sys.executable, str(exc))
    156         sys.exit(msg)
    157     pkg_name = mod_name.rpartition('.')[0]
    158     main_globals = sys.modules["__main__"].__dict__
    159     if alter_argv:
    160         sys.argv[0] = fname
    161     return _run_code(code, main_globals, None,
--> 162                      "__main__", fname, loader, pkg_name)
    163 
    164 def run_module(mod_name, init_globals=None,
    165                run_name=None, alter_sys=False):
    166     """Execute a module's code without importing it
    167 
    168        Returns the resulting top level namespace dictionary
    169     """
    170     mod_name, loader, code, fname = _get_module_details(mod_name)
    171     if run_name is None:
    172         run_name = mod_name
    173     pkg_name = mod_name.rpartition('.')[0]
    174     if alter_sys:
    175         return _run_module_code(code, init_globals, run_name,
    176                                 fname, loader, pkg_name)
    177     else:

/usr/lib/python2.7/runpy.pyc in _run_code(code=<code object <module> at 0x8b71770, file "/usr/l...ython2.7/dist-packages/ipdb/__main__.py", line 1>, run_globals={'__builtins__': {'ArithmeticError': <type 'exceptions.ArithmeticError'>, 'AssertionError': <type 'exceptions.AssertionError'>, 'AttributeError': <type 'exceptions.AttributeError'>, 'BaseException': <type 'exceptions.BaseException'>, 'BufferError': <type 'exceptions.BufferError'>, 'BytesWarning': <type 'exceptions.BytesWarning'>, 'DeprecationWarning': <type 'exceptions.DeprecationWarning'>, 'EOFError': <type 'exceptions.EOFError'>, 'Ellipsis': Ellipsis, 'EnvironmentError': <type 'exceptions.EnvironmentError'>, ...}, '__file__': '/tmp/test.py', '__name__': '__main__', 'a': 1, 'b': 0}, init_globals=None, mod_name='__main__', mod_fname='/usr/local/lib/python2.7/dist-packages/ipdb/__main__.py', mod_loader=<pkgutil.ImpLoader instance>, pkg_name='ipdb')
     57 
     58     def __exit__(self, *args):
     59         self.value = self._sentinel
     60         sys.argv[0] = self._saved_value
     61 
     62 def _run_code(code, run_globals, init_globals=None,
     63               mod_name=None, mod_fname=None,
     64               mod_loader=None, pkg_name=None):
     65     """Helper to run code in nominated namespace"""
     66     if init_globals is not None:
     67         run_globals.update(init_globals)
     68     run_globals.update(__name__ = mod_name,
     69                        __file__ = mod_fname,
     70                        __loader__ = mod_loader,
     71                        __package__ = pkg_name)
---> 72     exec code in run_globals
        global path_hooksR5 = undefined
        global R = undefined
        global t = undefined
        global NullImporter = undefined
        global path_namet = undefined
        global cachet = undefined
        global importert = undefined
        global hook = undefined
        global s = undefined
        global usr = undefined
        global lib = undefined
        global python2 = undefined
        global runpy.pyt = undefined
        global _get_importer = <function _get_importer at 0xb7839c34>
        global c = undefined
        global C = undefined
        global sg = undefined
        global d = undefined
        global Wd = undefined
        global QX = undefined
        global k = undefined
        global rc = undefined
        global j = undefined
        global QXn = undefined
        global S = undefined
        global Nt = undefined
        global rbt = undefined
        global rUt = undefined
        global openR = undefined
        global compilet = undefined
        global read = undefined
        global RG = undefined
        global fR = undefined
        global _get_code_from_file = <function _get_code_from_file at 0xb7839c6c>
        global r = undefined
        global n = undefined
        global rR = undefined
        global St = undefined
        global z = undefined
     73     return run_globals
     74 
     75 def _run_module_code(code, init_globals=None,
     76                     mod_name=None, mod_fname=None,
     77                     mod_loader=None, pkg_name=None):
     78     """Helper to run code in new namespace with sys modified"""
     79     with _TempModule(mod_name) as temp_module, _ModifiedArgv0(mod_fname):
     80         mod_globals = temp_module.module.__dict__
     81         _run_code(code, mod_globals, init_globals,
     82                   mod_name, mod_fname, mod_loader, pkg_name)
     83     # Copy the globals of the temporary module, as they
     84     # may be cleared when the temporary module goes away
     85     return mod_globals.copy()
     86 
     87 

/tmp/test.py in <module>()
     77         except SystemExit:
     78             # In most cases SystemExit does not warrant a post-mortem session.
     79             print "The program exited via sys.exit(). Exit status: ",
     80             print sys.exc_info()[1]
     81         except:
     82             traceback.print_exc()
     83             print "Uncaught exception. Entering post mortem debugging"
     84             print "Running 'cont' or 'step' will restart the program"
     85             t = sys.exc_info()[2]
     86             pdb.interaction(None, t)
     87             print "Post mortem debugger finished. The " + mainpyfile + \
     88                   " will be restarted"
     89 
     90 
     91 if __name__ == '__main__':
---> 92     main()
     93 
     94 
     95 
     96 
     97 
     98 
     99 
    100 
    101 
    102 
    103 
    104 
    105 
    106 
    107 

/tmp/test.py in main()
     59 
     60     # Replace pdb's dir with script's dir in front of module search path.
     61     sys.path[0] = os.path.dirname(mainpyfile)
     62 
     63     # Note on saving/restoring sys.argv: it's a good idea when sys.argv was
     64     # modified by the script being debugged. It's a bad idea when it was
     65     # changed by the user from the command line. There is a "restart" command
     66     # which allows explicit specification of command line arguments.
     67     pdb = Pdb(def_colors)
     68     while 1:
     69         try:
     70             pdb._runscript(mainpyfile)
     71             if pdb._user_requested_quit:
     72                 break
     73             print "The program finished and will be restarted"
---> 74         except Restart:
     75             print "Restarting", mainpyfile, "with arguments:"
     76             print "\t" + " ".join(sys.argv[1:])
     77         except SystemExit:
     78             # In most cases SystemExit does not warrant a post-mortem session.
     79             print "The program exited via sys.exit(). Exit status: ",
     80             print sys.exc_info()[1]
     81         except:
     82             traceback.print_exc()
     83             print "Uncaught exception. Entering post mortem debugging"
     84             print "Running 'cont' or 'step' will restart the program"
     85             t = sys.exc_info()[2]
     86             pdb.interaction(None, t)
     87             print "Post mortem debugger finished. The " + mainpyfile + \
     88                   " will be restarted"
     89 

NameError: global name 'Restart' is not defined

**********************************************************************

Oops, IPython crashed. We do our best to make it stable, but...

A crash report was automatically generated with the following information:
  - A verbatim copy of the crash traceback.
  - A copy of your input history during this session.
  - Data on your current IPython configuration.

It was left in the file named:
    '/home/bezalel/.ipython/IPython_crash_report.txt'
If you can email this file to the developers, the information in it will help
them in understanding and correcting the problem.

You can mail it to: Fernando Perez at [email protected]
with the subject 'IPython Crash Report'.

If you want to do it now, the following command will work (under Unix):
mail -s 'IPython Crash Report' [email protected] < /home/bezalel/.ipython/IPython_crash_report.txt

To ensure accurate tracking of this issue, please file a report about it at:
https://bugs.launchpad.net/ipython/+filebug

Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/IPython/CrashHandler.py", line 157, in __call__
    report.write(self.make_report(traceback))
  File "/usr/local/lib/python2.7/dist-packages/IPython/CrashHandler.py", line 215, in make_report
    rpt_add('BZR revision   : %s \n\n' % Release.revision)
AttributeError: 'module' object has no attribute 'revision'

Original exception was:
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/ipdb/__main__.py", line 92, in <module>
    main()
  File "/usr/local/lib/python2.7/dist-packages/ipdb/__main__.py", line 74, in main
    except Restart:
NameError: global name 'Restart' is not defined

Relicense as PSF-compatible?

I was hoping to contribute to this module, but as both Python itself and IPython are permissively licensed, it might make sense for this to also be permissively licensed. If not, I'll eventually make something MIT licensed from scratch that meets my needs.

Python 3 compatible

Please consider a patch below to make ipdb Python 3 compatible. Thanks.

--- old/main.py 2010-08-01 03:19:29 +0000
+++ new/main.py 2010-08-01 03:08:47 +0000
@@ -67,7 +67,7 @@

def pm():

  • post_mortem(sys.last_traceback)
  • post_mortem(sys.exc_info()[2] if sys.version_info.major >= 3 else sys.last_traceback)

def run(statement, globals=None, locals=None):
@@ -84,12 +84,12 @@

def main():
if not sys.argv[1:] or sys.argv[1] in ("--help", "-h"):

  •    print "usage: ipdb.py scriptfile [arg] ..."
    
  •    print("usage: ipdb.py scriptfile [arg] ...")
     sys.exit(2)
    

    mainpyfile = sys.argv[1] # Get script filename
    if not os.path.exists(mainpyfile):

  •    print 'Error:', mainpyfile, 'does not exist'
    
  •    print('Error:', mainpyfile, 'does not exist')
     sys.exit(1)
    

    del sys.argv[0] # Hide "pdb.py" from argument list
    @@ -107,22 +107,22 @@
    pdb._runscript(mainpyfile)
    if pdb._user_requested_quit:
    break

  •        print "The program finished and will be restarted"
    
  •        print("The program finished and will be restarted")
     except Restart:
    
  •        print "Restarting", mainpyfile, "with arguments:"
    
  •        print "\t" + " ".join(sys.argv[1:])
    
  •        print("Restarting", mainpyfile, "with arguments:")
    
  •        print("\t" + " ".join(sys.argv[1:]))
     except SystemExit:
         # In most cases SystemExit does not warrant a post-mortem session.
    
  •        print "The program exited via sys.exit(). Exit status: ",
    
  •        print sys.exc_info()[1]
    
  •        print("The program exited via sys.exit(). Exit status: ",)
    
  •        print(sys.exc_info()[1])
     except:
         traceback.print_exc()
    
  •        print "Uncaught exception. Entering post mortem debugging"
    
  •        print "Running 'cont' or 'step' will restart the program"
    
  •        print("Uncaught exception. Entering post mortem debugging")
    
  •        print("Running 'cont' or 'step' will restart the program")
         t = sys.exc_info()[2]
         pdb.interaction(None, t)
    
  •        print "Post mortem debugger finished. The " + mainpyfile + \
    
  •              " will be restarted"
    
  •        print("Post mortem debugger finished. The " + mainpyfile + \
    
  •              " will be restarted")
    

    if name == 'main':
    main()

post-mortem debugging doesn't work

When saved and run as

python test.py

with python 2.6.5, ipython 0.11, and ipdb 0.5 installed, the following code

print 'before'
from ipdb import pm; pm()
print 'after'

results in the following exception:

/tmp/test.py in <module>()
      2 
      3 #from ipdb import set_trace; set_trace()

----> 4 from ipdb import pm; pm()
      5 
      6 print 'after'

/usr/lib/python2.6/site-packages/ipdb/__main__.pyc in pm()
     53 
     54 def pm():
---> 55     post_mortem(sys.last_traceback)
     56 
     57 

AttributeError: 'module' object has no attribute 'last_traceback'

copy some features from pdb++

While I prefer ipdb due to its closer link with ipython, pdb++ does have some nice feature, like sticky mode (automatic calling of list after each step, highlighting current position) and expression display. Are there any plans to include something like this?

Thanks

Doesn't work with python 3.3

Trying ipdb 0.7 from PyPI and I get:

matej@wycliff: html2text (fix_tests)$ python3 -mipdb test/test_html2text.py 
Traceback (most recent call last):
  File "/usr/lib64/python3.3/runpy.py", line 140, in _run_module_as_main
    mod_name, loader, code, fname = _get_module_details(mod_name)
  File "/usr/lib64/python3.3/runpy.py", line 110, in _get_module_details
    return _get_module_details(pkg_main_name)
  File "/usr/lib64/python3.3/runpy.py", line 102, in _get_module_details
    loader = get_loader(mod_name)
  File "/usr/lib64/python3.3/pkgutil.py", line 482, in get_loader
    return find_loader(fullname)
  File "/usr/lib64/python3.3/pkgutil.py", line 499, in find_loader
    pkg = importlib.import_module(pkg_name)
  File "/usr/lib64/python3.3/importlib/__init__.py", line 88, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1525, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 586, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1023, in load_module
  File "<frozen importlib._bootstrap>", line 1004, in load_module
  File "<frozen importlib._bootstrap>", line 562, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 869, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "/home/matej/.local/lib/python3.3/site-packages/ipdb/__init__.py", line 16, in <module>
    from ipdb.__main__ import set_trace, post_mortem, pm, run, runcall, runeval, launch_ipdb_on_exception
  File "/home/matej/.local/lib/python3.3/site-packages/ipdb/__main__.py", line 118
    print "usage: ipdb.py scriptfile [arg] ..."
                                              ^
SyntaxError: invalid syntax

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.