pdb

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

十年热恋 提交于 2019-11-28 21:20:32
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 following expression fails: (Pdb) [x*a for x in nums] *** NameError: global name 'a' is not defined The above works fine in Python 2.7. Is this a bug or I am missing something? Update : See the new accepted answer. This was indeed a bug (or a problematic design) which has been addressed now by introducing a new command and mode in pdb. if you type interact in your [i]pdb

Python debugger: Stepping into a function that you have called interactively

让人想犯罪 __ 提交于 2019-11-28 21:01:36
Python is quite cool, but unfortunately, its debugger is not as good as perl -d. One thing that I do very commonly when experimenting with code is to call a function from within the debugger, and step into that function, like so: # NOTE THAT THIS PROGRAM EXITS IMMEDIATELY WITHOUT CALLING FOO() ~> cat -n /tmp/show_perl.pl 1 #!/usr/local/bin/perl 2 3 sub foo { 4 print "hi\n"; 5 print "bye\n"; 6 } 7 8 exit 0; ~> perl -d /tmp/show_perl.pl Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(/tmp/show_perl.pl

C++访问sqlite3的初体验

情到浓时终转凉″ 提交于 2019-11-28 20:33:24
Sqlite确实是一个比较好的本地数据库,从接触它的时候就喜欢上了它,它可以在很多情况下简化应用。不过以前都是在Java里面使用,或者Linux C下使用的,现在有个项目(C++)可能我会用到sqlite做数据持久化,所以先热热身。 第一步:下载相关文件 首先到这里下载sqlite-source-3_6_12.zip、sqlite-3_6_12.zip、 sqlitedll-3_6_12.zip三个包,并分别解压。 第二步:生成SQLite的lib文件 cmd进入命令行后输入: LIB /DEF:SQLITE3.DEF /MACHINE:IX86 如果找不到命令LIB,则需要将Microsoft Visual Studio\VC98\Bin这个目录添加到环境变量里。这样就生成了sqlite3.lib文件,我们在后面需要用到这个库,用于链接win32程序 第三步:编写测试工程 新建项目,将sqlite3.h(在源码包里)、sqlite3.dll、sqlite3.lib设置到工程环境里,或者直接拷贝到工程目录下。 然后我们将cmd切换到sqlite3的目录下,里面有个sqlite3.exe。执行命令: > sqlite3 D:\sql.db ;生成sql.db的数据库文件 sqlite3 > create table test_tab (f1 int, f2 long);

How to quit ipdb while in post-mortem debugging?

可紊 提交于 2019-11-28 19:16:13
I like to inspect error in a Python script by using: $ python3 -m pdb my_script.py This drops me into a pdb prompt from where I can c continue the execution, and when it hits error, I can inspect the variables and then q quit the script execution to get back to my shell. I tried the same with iPython debugger module, since it is more colorful: $ python3 -m ipdb my_script.py However, I am not able to quit the debugger once I am done inspecting the error. Using the q quit command just keeps switching it between re-executing the script and post-mortem mode: $ python3 -m ipdb my_script.py ipdb> c

Can I debug with python debugger when using py.test somehow?

拜拜、爱过 提交于 2019-11-28 19:04:31
I am using py.test for unit testing my python program. I wish to debug my test code with the python debugger the normal way (by which I mean pdb.set_trace() in the code) but I can't make it work. Putting pdb.set_trace() in the code doesn't work (raises IOError: reading from stdin while output is captured). I have also tried running py.test with the option --pdb but that doesn't seem to do the trick if I want to explore what happens before my assertion. It breaks when an assertion fails, and moving on from that line means terminating the program. Does anyone know a way to get debugging, or is

Docker-compose and pdb

不羁的心 提交于 2019-11-28 16:58:18
I see that I'm not the first one to ask the question but there was no clear answer to this: How to use pdb with docker-composer in Python development? When you ask uncle Google about django docker you get awesome docker-composer examples and tutorials and I have an environment working - I can run docker-compose up and I have a neat developer environment but the PDB is not working (which is very sad). I can settle with running docker-compose run my-awesome-app python app.py 0.0.0.0:8000 but then I can access my application over http://127.0.0.1:8000 from the host (I can with docker-compose up )

Python Unit Testing: Automatically Running the Debugger when a test fails

三世轮回 提交于 2019-11-28 15:59:16
Is there a way to automatically start the debugger at the point at which a unittest fails? Right now I am just using pdb.set_trace() manually, but this is very tedious as I need to add it each time and take it out at the end. For Example: import unittest class tests(unittest.TestCase): def setUp(self): pass def test_trigger_pdb(self): #this is the way I do it now try: assert 1==0 except AssertionError: import pdb pdb.set_trace() def test_no_trigger(self): #this is the way I would like to do it: a=1 b=2 assert a==b #magically, pdb would start here #so that I could inspect the values of a and b

How to exit pdb and allow program to continue?

风流意气都作罢 提交于 2019-11-28 15:02:39
问题 I'm using the pdb module to debug a program. I'd like to understand how I can exit pdb and allow the program to continue onward to completion. The program is computationally expensive to run, so I don't want to exit without the script attempting to complete. continue doesn't seems to work. How can I exit pdb and continue with my program? 回答1: continue should "Continue execution, only stop when a breakpoint is encountered", so you've got a breakpoint set somewhere. To remove the breakpoint (if

Python中如何Debug

拈花ヽ惹草 提交于 2019-11-28 13:27:14
debug是编码是非常重要的调试技巧,通过在运行过程中设置断点,帮助开发人员更好的理解运行过程。 Python中debug不像JAVA或者C++那样在IDE中设置断点那么直观。 Python的debug有两种方式: 1.在 命令行 中运行, 2.在 脚本 当中运行。两种方式都需要使用 pdb模块。 方式一:在命令行中运行 $ python -m pdb my_script.py 方式二:脚本中运行 在需要设置断点的地方,插入方法 pdb.set_trace() import pdb def make_bread(): pdb.set_trace() return "I don't have time" print(make_bread()) 命令: 在进入调试状态之后,就可以输入命令进行调试了。 c: (continue)继续执行 w:(words)显示当前行的上下文信息 a:(arguments)打印当前函数的参数列表 s:(stop)执行当前行,并在顶一个可能的时机停止 n:(next)继续执行直到当前函数的下一行或者函数返回值 来源: http://www.cnblogs.com/bradleon/p/5938839.html

How to debug a Python module run with python -m from the command line?

偶尔善良 提交于 2019-11-28 08:59:11
I know that a Python script can be debugged from the command line with python -m pdb my_script.py if my_script.py is a script intended to be run with python my_script.py . However, a python module my_module.py should be run with python -m my_module . Even scripts that contain relative imports should be run with python -m . How can I run python -m my_module under pdb 's control? The following does not work : python -m pdb -m my_module You can't do it now, because -m terminates option list python -h ... -m mod : run library module as a script (terminates option list) ... That means it's mod's