pdb

Python pdb on python script run as package

孤者浪人 提交于 2019-12-23 07:55:21
问题 I have a python program that I usually run as a part of a package: python -m mymod.client in order to deal with relative imports inside "mymod/client.py." How do I run this with pdb - the python debugger. The following does not work: python -m pdb mymod.client It yields the error: Error: mymod.client does not exist EDIT #1 (to address possible duplicity of question) My question isn't really about running two modules simultaneously python, rather it is about how to use pdb on a python script

How to set breakpoints in a library module (pdb)

 ̄綄美尐妖づ 提交于 2019-12-23 07:49:32
问题 I am debugging a python script which sys.path looks like sys.path = ['','home/my_library', ..] I'm having troubles to set a breakpoint in a module from my_library while using pdb. The script imports the library with: import my_library as foo In turn, my_library makes its module(s) available by: from my_module import bar How can address my_module's code while running pdb on my script? PS: I have tried the followings without success: b my_module:1 b my_library.my_module:1 b my_library.bar:1 b

Day-10: 错误、调试和测试

百般思念 提交于 2019-12-23 02:06:04
  程序运行时,会遇到各种各样的错误。   编写错误叫做bug,而另一类由于运行过程中无法预测的,比如写文件时,磁盘满了,写不进去;或者从网络抓取数据,网络突然掉了。这些错误称为异常,程序中需要对异常进行处理,使得程序能够运行下去。 错误处理   Python中,程序运行错误时,如果错误没有捕获,它会一直往上抛,最后被Python解释器捕获,打印一个错误。 # err.py: def foo(s): return 10 / int(s) def bar(s): return foo(s) * 2 def main(): bar('0') main() $ python err.py Traceback (most recent call last): File "err.py", line 11, in <module> main() File "err.py", line 9, in main bar('0') File "err.py", line 6, in bar return foo(s) * 2 File "err.py", line 3, in foo return 10 / int(s) ZeroDivisionError: integer division or modulo by zero 从上到下,错误会一层层的反馈,直到显示最终出错的地方。   try..

Debugging a python application that just sort of “hangs”

我的未来我决定 提交于 2019-12-22 09:56:55
问题 I have an event-driven application, written in python. After a while (usually >1 week) it appears to just stop responding to events. When this happens, I just ctrl-C and re-run and all is well-again. However, it's kind of annoying that this keeps happening and I have no idea what's causing it. Is there a way I can run my application that when this occurs and the application is no longer accepting connections, I can drop into a debugger and see what it's doing and why it's not taking

“SyntaxError: unexpected EOF while parsing” while iterating a dictionary in PDB

允我心安 提交于 2019-12-22 04:08:22
问题 I have a pdb trace set inside a GET request. I want to print all the attributes of the request object. I am trying the following, in pdb: (Pdb) request <GET /foo HTTP/1.1> (Pdb) for d in dir(request): *** SyntaxError: unexpected EOF while parsing (<stdin>, line 1) I am sure there is something fundamental I am missing here. 回答1: You can't enter multi-line statements in pdb . You can use the commands command if the code block is to be executed on a break point, though; help commands for more

Emacs python-mode: Keyboard shortcuts for pdb step-by-step debugging

China☆狼群 提交于 2019-12-21 12:29:07
问题 I was wondering if there is a way to associate: n RET (next) p RET (previous) c RET (continue) C-x SPC RET (set/clear breakpoint) with function keys F1 - F12 or other keyboard shortcuts. The idea is to emulate the keyboard shortcuts that other IDEs have for debugging (e.g. Visual Studio, MATLAB, etc.). Is this already supported by python-mode? Are there any Emacs modes that can be used to complement python-mode for debugging purposes? 回答1: You always can define own key-bindings in Emacs.

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

半世苍凉 提交于 2019-12-21 06:57:13
问题 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

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

╄→尐↘猪︶ㄣ 提交于 2019-12-21 04:55:14
问题 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. 回答1: Have you tried pytest-ipdb? Looks like it's exactly what you are looking for? 回答2: Use this option to set custom debugger: -

“Browse To Find Source” in Visual Studio 2010

谁说我不能喝 提交于 2019-12-20 08:49:07
问题 When is "Browse To Find source" enabled in Visual Studio 2010? (see below) In addition, I want to have it enabled so that I could browse to already-downloaded source code files from http://referencesource.microsoft.com/. This would be useful since Microsoft doesn't always release PDB/source code at the same time with their latest patches. So if I want to step for example into DateTime, I really don't care about the latest patches which didn't involve DateTime. I just want to browse to its

How do I manipulate a variable whose name conflicts with PDB commands?

做~自己de王妃 提交于 2019-12-20 08:32:51
问题 My code is, for better or worse, rife with single letter variables (it's physics stuff, so those letters are meaningful), as well as NumPy's, which I'm often interacting with. When using the Python debugger, occasionally I'll want to look at the value of, say, n . However, when I hit n<enter> , that's the PDB command for (n)ext , which has a higher priority. print n works around looking at it, but how can I set it? 回答1: Use an exclamation mark ! before a statement to have it run : python -m