0

i am using the python shell to try to do debugging

i set a breakpoint

i did:

>>> import pdb
>>> import mymodule
>>> pdb.run('mymodule.test()')

but it is just running my program without stopping at the breakpoint!

what am i donig wrong?

2
  • For python version below 3.7 use import pdb;pdb.set_trace() and for above python 3.7 version use breakpoint() Commented Nov 26, 2019 at 14:28
  • Does this answer your question? Getting started with the Python debugger, pdb Commented Nov 26, 2019 at 14:31

2 Answers 2

4

How did you set a breakpoint? Try adding the line in your code:

import pdb
pdb.set_trace()

and then run it. If you're in the pdb shell, then "break foo.py:45" will break on line 45 of file foo.py.

Here are some useful commands:

h    help, list commands
s    step through current line
n    step to next line
u    go up the stack
c    continue execution

Check the full list by typing 'h'. And "help X" will give you help on command X. Also, see this tutorial:

Sign up to request clarification or add additional context in comments.

Comments

2

The typical usage to break into the debugger from a running program is to insert

import pdb; pdb.set_trace()

at the location you want to break into the debugger. You can then step through the code following this statement, and continue running without the debugger using the c command.

The typical usage to inspect a crashed program is:

>>> import pdb
>>> import mymodule
>>> mymodule.test()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "./mymodule.py", line 4, in test
    test2()
  File "./mymodule.py", line 3, in test2
    print spam
NameError: spam
>>> pdb.pm()
> ./mymodule.py(3)test2()
-> print spam
(Pdb)

The Python site offers a very elaborate tutorial for pdb. Go to http://docs.python.org/library/pdb.html.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.