History across ipdb sessions
Asked Answered
E

3

7

This question has been asked before, but I couldn't find a good answer. So, I am trying to ask again.

I would like my ipdb to remember commands across sessions. Right now, it can pull up commands executed in Ipython sessions but not from old ipdb sessions. It would be a huge time saver, if I could have this feature.

Does anyone have a solution to this problem?

Economize answered 7/11, 2014 at 22:9 Comment(0)
D
5

I had your same problem, so I forked the project and add a patch for persistent history. You can install the forked version of ipdb with pip:

pip install git+https://github.com/michelesr/ipdb.git

Just make sure that your IPython version is 5.0 or higher. Implementation info can be found in this article.

Dobb answered 22/11, 2016 at 17:50 Comment(1)
I get that forking desire often with ipdb.Diastasis
O
1

If you are wiling to use another debugger, trepan has does save history across sessions.

Oui answered 3/7, 2015 at 2:23 Comment(0)
S
1
  • Create a file with the following content
  • Import that file with execfile(...) in your ~/.pdbrc file
def use_file_history():
    import os
    from IPython.terminal.debugger import TerminalPdb
    from prompt_toolkit.history import FileHistory
    cmdloop = TerminalPdb.cmdloop
    def cmdloop_prime(self, intro=None):
        fname = os.path.join(os.path.expanduser('~'), '.ipdb_history')
        self._pt_app.buffer.history = FileHistory(fname)
        self._pt_app.buffer.reset()
        cmdloop(self, intro)
    TerminalPdb.cmdloop = cmdloop_prime

use_file_history()
del use_file_history

PS—you can find this code, and more patches, in this gist with ipdb patches

Savarin answered 3/5, 2020 at 8:30 Comment(1)
I get *** NameError: name 'execfile' is not defined when I try and do this. Is execfile pdb only, not ipdb? Am I missing something else? Can you post a minimal ~/.pdbrc example please? (ipdb==0.13.13, ipython==7.31.1)Uniform

© 2022 - 2024 — McMap. All rights reserved.