pdb

In the Python debugger pdb, how do you exit interactive mode without terminating the debugging session

瘦欲@ 提交于 2019-12-03 22:26:41
Using python 3.5.1 When I run a script using the python debugger module: [home]# python -m pdb myscript.py This starts a debug session: > /somepath/to/myscript.py(1)<module>() -> import os (Pdb) If I want to enter an interactive terminal from within the debug session I can issue the interact command: (Pdb) interact *interactive* >>> Now I can interact with th code as if I was in a running python interactive mode, with access to any functions or variable in scope of the script running in the debugger at the time I entered interact mode. When I issue the command to exit the interactive mode (to

'NameError: global name is not defined' under pdb, for dictionary that does exist

一个人想着一个人 提交于 2019-12-03 16:09:32
I've encountered an issue re scopes in a lambda function. I can successfully output foo to stdout but I get an error when using max() including a lambda - see simplified code below... All in all, I am trying find the largest value for a nested key budget within an unknown number of first order keys. (Pdb) foo = self.some_method() # some_method() returns a dict, printed in the next step (Pdb) pp foo {'1': {'count': 1, 'extra_data': {'activity-count': 1, 'budget': 0, [...MORE KEY-VALUE PAIRS HERE...] 'version': 1}, [...LOTS MORE KEY-VALUE PAIRS HERE...] 'elements_total': defaultdict(<type 'int'>

Use ipdb instead of pdb with py.test --pdb option

二次信任 提交于 2019-12-03 14:16:11
I want to use ipdb instead of pdb with py.test --pdb option. Is this possible? If so, how? Clearly, I can use import ipdb; ipdb.set_trace() in the code but that requires to run the test, watch it fail, open a file, find the point of failure in said file, write the above line, re-run the tests. Lots of hassle if I could have something that by passes all of that. Have you tried pytest-ipdb ? Looks like it's exactly what you are looking for? Use this option to set custom debugger: --pdbcls=IPython.terminal.debugger:Pdb It can also be included in pytest.ini using addopts : [pytest] addopts = -

How do I change a value while debugging python with pdb?

心不动则不痛 提交于 2019-12-03 10:42:31
I want to run pdb, step through the code, and at some point change the value pointed at by some name. So I might want to change the value pointed at by the name 'stationLat'. But it seems I can't. Here's the example: >>> import extractPercentiles >>> import pdb >>> pdb.run( "extractPercentiles.extractOneStation()" ) > <string>(1)<module>()->None (Pdb) s --Call-- > /scratch/extractPercentiles.py(96)extractOneStation() -> def extractOneStation() : (Pdb) tbreak 132 Breakpoint 3 at /scratch/extractPercentiles.py:132 (Pdb) c Deleted breakpoint 3 > /scratch/extractPercentiles.py(132

PDB won't stop on breakpoint

折月煮酒 提交于 2019-12-03 10:04:46
I'm quite new with debugging directly with pdb and I am having some issues debugging my Django application. Here is what I'm doing: python -m pdb manage.py runserver (pdb) b core/views.py:22 Breakpoint 2 at /Users/raphaelcruzeiro/Documents/Projects/pdb_test/core/views.py:22 (Pdb) c However the execution passes directly through the breakpoint. Am I missing some command? The manual doesn't elaborate on setting a breakpoint anymore than this. I've been through the same problem. Try something like python -m pdb ./manage.py runserver --nothreading --noreload 127.0.0.1:8080 . It solved the issue for

Python调试工具

痴心易碎 提交于 2019-12-03 10:01:14
1. 日志 通过日志或者print来打印变量。必要时可以打印 locals() 和 globals() 建议使用logging.debug()来代替print,这样到了正式环境,就可以统一删除这些日志。 2.trace Python有个trace模式,可以打印整个程序的执行流 # encoding=utf8 def f(): print 'aa' if __name__ == '__main__': f() 例如这段简单的程序,执行 python -mtrace --trace test.py 就会输出下面的日志: --- modulename: test, funcname: <module> # test模块,module级函数 test.py(2): def f(): #test.py的第2行,执行def f命令定义函数 test.py(6): if __name__ == '__main__': test.py(7): f() --- modulename: test, funcname: f test.py(3): print 'aa' aa --- modulename: trace, funcname: _unsettrace trace.py(80): sys.settrace(None) 可以详细得看到这代代码在Python中的执行流程。 当代码比较复杂

Python - start interactive debugger when exception would be otherwise thrown

允我心安 提交于 2019-12-03 09:00:21
问题 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 trace after which I have to use to figure out where to insert breakpoints and then restart the program to debug it. I know that simply making the debugger start instead of throwing an exception would not make sense because any exception can be

Is it possible to step backwards in pdb?

蹲街弑〆低调 提交于 2019-12-03 05:28:38
问题 After I hit n to evaluate a line, I want to go back and then hit s to step into that function if it failed. Is this possible? The docs say: j(ump) lineno Set the next line that will be executed. Only available in the bottom-most frame. This lets you jump back and execute code again, or jump forward to skip code that you don’t want to run. 回答1: The GNU debugger, gdb: It is extremely slow, as it undoes single machine instruction at a time. The Python debugger, pdb: The jump command takes you

gdb, pdb笔记

匆匆过客 提交于 2019-12-03 05:04:59
gdb gdb --args yourprogram 常用命令 r(run):从头开始运行 c(continue):继续运行 b(breakpoint) filepath:line or namespace::function(type):断点 s(step):运行当前行代码,会进入子函数 n(next):运行当前行代码,不会进入子函数 bt(backtrace):查看当前函数栈 until [line]:运行直到推出循环体,或者到指定行号 d(delete) n:删除第n个断点 disable n:暂停第n个断点 clear n:清除第n行的断点 info [threads, breakpoints]:查看线程,断点信息 t(thread) n:进入第n个线程 Ctrl+A+X可以开关图形化界面 p(print) x:输出x watch x:监控x,当x发生变化的时候停住并显示x display x:单步调试时,每一次都重新打印x q(quit):退出gdb pdb python3 -m pdb yourprogram or add "import pdb;pdb.set_trace()" in your program 用法和gdb很相似 但是没有图形化界面,也不能调试多线程 来源: https://www.cnblogs.com/Randolph87/p/11779183