Questions tagged [pdb]

This tag refers to the Python debugger. For questions pertaining to the protein database file format, use the protein-database tag. For questions pertaining to Microsoft Program Database files, use the pdb-files tag.

The Python Debugger supports breakpoints, single stepping, inspection of stack frames, source code listing, and evaluation of arbitrary Python code in the context of any stack frame. It also supports post-mortem debugging and can be called under program control.

For questions pertaining to the protein database file format (.pdb), use the tag.

For questions pertaining to Microsoft "Program Database" (.pdb) files, use the tag.

880 questions
26
votes
3 answers

Possible bug in pdb module in Python 3 when using list generators

After running this code in Python 3: import pdb def foo(): nums = [1, 2, 3] a = 5 pdb.set_trace() foo() The following expressions work: (Pdb) print(nums) [1, 2, 3] (Pdb) print(a) 5 (Pdb) [x for x in nums] [1, 2, 3] but the…
Loax
  • 615
  • 5
  • 11
25
votes
3 answers

conditional breakpoint using pdb

Sounds like I'm missing something extremely simple, I'm trying to set a breakpoint in my python code using: if(some condition): pdb.set_trace() My error in the code comes after a large number of iterations..difficult to debug using print…
sanjay
  • 647
  • 1
  • 6
  • 14
25
votes
3 answers

pdb/ipdb for python break on editable condition

Say I have code the following code: for i in range(100): print i In general I can add one line to the code as: for i in range(100): import ipdb;ipdb.set_trace() print i However, now I want to debug it at condition of i == 10, and I…
shelper
  • 10,053
  • 8
  • 41
  • 67
24
votes
4 answers

How do you pass script arguments to pdb (Python)?

I've got python script (ala #! /usr/bin/python) and I want to debug it with pdb. How can I pass arguments to the script? I have a python script and would like to debug it with pdb. Is there a way that I can pass arguments to the scripts?
Glenn
24
votes
1 answer

How do you exit PDB /and/ kill the program?

How do you kill PDB and the program it's running, similar to LLDB's proc kill; exit or exit (y) commands? Ctrl+D isn't working and all the questions I see on here are how to exit while keeping the program running. However, I'm sitting in a PDB…
Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
24
votes
5 answers

Get last exception in pdb

Is there a way to examine the last exception when in pdb/before entering pdb? (Using python 2.7.5). Immediately (yes, I enter no other commands at all) after an exception being raised in my code, I do sys.exc_info(); this just results in (None,…
Marcin
  • 48,559
  • 18
  • 128
  • 201
24
votes
2 answers

pdb cannot break in another thread?

Consider this multi-threaded program: import threading class SomeThread(threading.Thread): def run(self): a = 1 print a def main(): print 'hola' someThread = SomeThread() someThread.start() if __name__ == '__main__': …
dim fish
  • 469
  • 1
  • 4
  • 12
23
votes
4 answers

Getting pdb in Emacs to use Python process from current virtualenv

I am debugging some python code in emacs using pdb and getting some import issues. The dependencies are installed in one of my bespoked virtualenv environments. Pdb is stubbornly using /usr/bin/python and not the python process from my virtualenv.…
codeasone
  • 1,953
  • 2
  • 23
  • 30
23
votes
7 answers

How to use `pytest` from Python?

I'm working in a project that recently switched to the pytest unittest framework. I was used to calling my tests from Eclipse, so that I can use the debugger (e.g. placing breakpoints to analyze how a test failure develops). Now this is no longer…
nikow
  • 21,190
  • 7
  • 49
  • 70
23
votes
3 answers

How to use ipdb.set_trace in a forked process

I use ipdb.set_trace() whenever I need to set a break point in my code. Right now, I'm trying to use it in a process that I've created using multiprocessing, while the code does stop, I can't type anything to continue debugging. Is there any way to…
Seanny123
  • 8,776
  • 13
  • 68
  • 124
23
votes
6 answers

Get IPython tab completion for ipdb

I have IPython(0.13.1) and ipdb(0.7) installed, I inserted the line import ipdb;ipdb.set_trace() in my script and ran python my_script.py. Now I am in the ipdb prompt and there is some autocompletion (e.g. a bare tab) but it's not the same as the…
Bentley4
  • 10,678
  • 25
  • 83
  • 134
22
votes
1 answer

PDB: How to inspect local variables of functions in nested stack frames?

Context: I'm running some python code thru PDB (Python debugger). When I set and subsequently hit a breakpoint, I can inspect the local variables using: (Pdb) locals() This prints out a nice dict of name, value pairs of the local variables in the…
Todd Ditchendorf
  • 11,217
  • 14
  • 69
  • 123
22
votes
4 answers

Python - start interactive debugger when exception would be otherwise thrown

Is there any way to make a python program start an interactive debugger, like what import pdb; pdb.set_trace() instead of actually throwing an exception? I know the difficulty of making this work, but it would be much more valuable than a huge stack…
NeuronQ
  • 7,527
  • 9
  • 42
  • 60
21
votes
4 answers

python pdb automatic pretty-printing

I find myself doing this in pdb quite often: import pprint pprint.PrettyPrinter().pprint(variable_of_interest) Is there a better way to pretty-print variables from pdb? I'm looking for something easier to type, and ideally something that's always…
nonagon
  • 3,271
  • 1
  • 29
  • 42
21
votes
1 answer

Get reference to the current exception

$ ./runtests.py -v tests/managers/test_customer.py:CustomerManagerTest.test_register_without_subscription --ipdb ... test_register_without_subscription (tests.managers.test_customer.CustomerManagerTest) ... - TRACEBACK…
warvariuc
  • 57,116
  • 41
  • 173
  • 227