pdb

Python 调试器之pdb,ipdb,pudb

会有一股神秘感。 提交于 2020-01-15 03:59:26
一般情况下服务器是没有图形界面的,那么在无图形界面的情况下对python进行debug呢 这里提了三种办法 这三者大体的原理和用法差不多,不过用ipdb的时候set_trace()这个函数可以直接用,下面我们以pdb为例子演示一下 使用PDB的方式有两种: 1. 单步执行代码,通过命令 python -m pdb xxx.py 启动脚本,进入单步执行模式 pdb命令行: 1)进入命令行Debug模式,python -m pdb xxx.py 2)h:(help)帮助 3)w:(where)打印当前执行堆栈 4)d:(down)执行跳转到在当前堆栈的深一层(个人没觉得有什么用处) 5)u:(up)执行跳转到当前堆栈的上一层 6)b:(break)添加断点 b 列出当前所有断点,和断点执行到统计次数 b line_no:当前脚本的line_no行添加断点 b filename:line_no:脚本filename的line_no行添加断点 b function:在函数function的第一条可执行语句处添加断点 7)tbreak:(temporary break)临时断点 在第一次执行到这个断点之后,就自动删除这个断点,用法和b一样 8)cl:(clear)清除断点 cl 清除所有断点 cl bpnumber1 bpnumber2... 清除断点号为bpnumber1

Django UnicodeDecodeError when using pdb

ぃ、小莉子 提交于 2020-01-14 19:38:05
问题 I've notice every time I put an: import pdb; pdb.set_trace() in My Spanish Django project, if I have a specific Unicode character in a string like: Gracias por tu colaboración I get a UnicodeDecodeError with an 'ordinal not in range(128)' in a Django Debug window. The problem is that I can not debug my application easily. On the other hand If I use ipdb I get things like: ERROR - failed to write data to stream: <open file '<stdout>', mode 'w' at 0x7f3d43e34140> I've googled to find a solution

How to specifiy path when using pdb in emacs?

别等时光非礼了梦想. 提交于 2020-01-13 13:28:11
问题 I am trying to use pdb in emacs. I need to change path to PYTHONPATH=lib . But when I typed Run pdb (like this): PYTHONPATH=lib pdb ./pychess . Emacs gives me an error saying the file PYTHONPATH=lib isn't found. How do I specify path when running pdb in emacs? In terminal PYTHONPATH=lib pdb ./pychess runs fine, but not in emacs. Oh I got it just type PYTHONPATH=lib emacs when launching emacs. Not sure about changing path after launching though... 回答1: you can try to set the environment

PDB won't stop on breakpoint

馋奶兔 提交于 2020-01-12 06:44:05
问题 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. 回答1: I've been through the same problem. Try

How can I debug manually typed expression and statements in pdb?

 ̄綄美尐妖づ 提交于 2020-01-11 05:11:32
问题 In pdb (or ipdb) we can execute statements and evaluate expressions with the ! or p commands: p expression Evaluate the expression in the current context and print its value. [!]statement Execute the (one-line) statement in the context of the current stack frame. The exclamation point can be omitted unless the first word of the statement resembles a debugger command. To set a global variable, you can prefix the assignment command with a global command on the same line So, for example, I can

python调试的几种方法

蹲街弑〆低调 提交于 2020-01-10 11:43:47
调试 From :https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683229901532c40b749184441dbd428d2e0f8aa50e000 程序能一次写完并正常运行的概率很小,基本不超过1%。总会有各种各样的bug需要修正。有的bug很简单,看看错误信息就知道,有的bug很复杂,我们需要知道出错时,哪些变量的值是正确的,哪些变量的值是错误的,因此,需要一整套调试程序的手段来修复bug。 第一种方法简单直接粗暴有效,就是用print把可能有问题的变量打印出来看看: print err.py def foo ( s ) : n = int ( s ) print '>>> n = %d' % n return 10 / n def main ( ) : foo ( '0' ) main() 执行后在输出中查找打印的变量值: $ python err.py > n = 0 Traceback ( most recent call last ) : .. . ZeroDivisionError: integer division or modulo by zero 用print最大的坏处是将来还得删掉它,想想程序里到处都是print

Python pdb command history not working on Windows

≡放荡痞女 提交于 2020-01-05 07:25:18
问题 I'm using Windows 7 + Cygwin + Python 2.6 + cmd prompt. Since yesterday, command line history stopped working with pdb. I used the following lines in my python code for interactive debugging. import pdb pdb.set_trace() Earlier, I was able to recall the command history with up arrow but it stopped working recently. I remember adding a few cygwin packages around the time it stopped working. If there's some easy/obvious way to find what caused the error please advise or else I'll try rolling

using ipdb for debugging python inside emacs

与世无争的帅哥 提交于 2020-01-02 05:34:10
问题 import pdb; pdb.set_trace() works fine when I run M-x pdb python manage.py runserver However import ipdb would cause the above statement to hang indefinately.. I hear great things about ipdb, how do I use it under emacs? Edit Just found out django has nothing to do with it, simple python file hangs as well. 来源: https://stackoverflow.com/questions/29425325/using-ipdb-for-debugging-python-inside-emacs

How to make pdb recognize that the source has changed between runs?

独自空忆成欢 提交于 2020-01-02 01:09:30
问题 From what I can tell, pdb does not recognize when the source code has changed between "runs". That is, if I'm debugging, notice a bug, fix that bug, and rerun the program in pdb (i.e. without exiting pdb), pdb will not recompile the code. I'll still be debugging the old version of the code, even if pdb lists the new source code. So, does pdb not update the compiled code as the source changes? If not, is there a way to make it do so? I'd like to be able to stay in a single pdb session in order

Get reference to the current exception

爱⌒轻易说出口 提交于 2020-01-01 08:39:11
问题 $ ./runtests.py -v tests/managers/test_customer.py:CustomerManagerTest.test_register_without_subscription --ipdb ... test_register_without_subscription (tests.managers.test_customer.CustomerManagerTest) ... - TRACEBACK -------------------------------------------------------------------- Traceback (most recent call last): File "/usr/lib/python2.7/unittest/case.py", line 331, in run testMethod() File "*****/tests/managers/test_customer.py", line 198, in test_register_without_subscription 1/0