python - ipdb中的 '*** Oldest frame'是什么意思?

标签 python python-3.x pdb ipdb

我正在尝试向服务器发出 http 请求并检查我返回的内容。但是,当我尝试使用 ipdb 浏览 HTTPResponse 对象 时,我不断收到 *** Oldest frame 并且我无法运行任何功能在我应该能够运行的对象上。这是用于获取的代码块,以及 ipdb 输出:

代码块:

for acc in sp_lost:
    url = 'http://www.uniprot.org/uniprot/?query=mnemonic%3a'+acc+'+active%3ayes&format=tab&columns=entry%20name'
    u = urllib.request.urlopen(url)
    ipdb.set_trace()

ipdb 输出:

ipdb> url
'http://www.uniprot.org/uniprot/?query=mnemonic%3aSPATL_MOUSE+active%3ayes&format=tab&columns=entry%20name'
ipdb> u
*** Oldest frame
ipdb> str(u)
'<http.client.HTTPResponse object at 0xe58e2d0>'
ipdb> type(u)
<class 'http.client.HTTPResponse'>
ipdb> u.url                      
*** Oldest frame
ipdb> u.url()         # <-- unable to run url() on object...?
*** Oldest frame
ipdb> 

*** Oldest frame 是什么意思,我怎样才能把这个对象变成更有用的东西,我可以在上面运行适当的函数?

最佳答案

u 是遍历堆栈帧的 PDB 命令。您已经处于“最上层”框架中。 help u 会告诉你更多相关信息:

u(p)
Move the current frame one level up in the stack trace
(to an older frame).

该命令与d(own)w(here)密切相关:

d(own)
Move the current frame one level down in the stack trace
(to a newer frame).
w(here)
Print a stack trace, with the most recent frame at the bottom.
An arrow indicates the "current frame", which determines the
context of most commands.  'bt' is an alias for this command.

如果要打印变量 u,请在其前面加上 ! 以使其不被调试器解释为调试命令:

!u
!u.url

或者使用print():

print(u)

help pdb 输出:

Commands that the debugger doesn't recognize are assumed to be Python statements and are executed in the context of the program being debugged. Python statements can also be prefixed with an exclamation point ('!').

Oldest frame 是堆栈中程序开始的帧;它是最古老的; Newest frame,堆栈的另一端,是 Python 正在执行代码的地方,也是当前执行的框架,如果您点击 c(ontinue),Python 将继续执行> 命令。

一个带有递归函数的小演示:

>>> def foo():
...     foo()
... 
>>> import pdb
>>> pdb.run('foo()')
> <string>(1)<module>()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) s
> <stdin>(2)foo()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) s
> <stdin>(2)foo()
(Pdb) s
--Call--
> <stdin>(1)foo()
(Pdb) w
  /Users/mj/Development/Libraries/buildout.python/parts/opt/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
  <string>(1)<module>()
  <stdin>(2)foo()
  <stdin>(2)foo()
> <stdin>(1)foo()
(Pdb) u
> <stdin>(2)foo()
(Pdb) u
> <stdin>(2)foo()
(Pdb) u
> <string>(1)<module>()
(Pdb) u
> /Users/mj/Development/Libraries/buildout.python/parts/opt/lib/python2.7/bdb.py(400)run()
-> exec cmd in globals, locals
(Pdb) u
*** Oldest frame

关于python - ipdb中的 '*** Oldest frame'是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17727993/

相关文章:

python - 使用 pdb 调试 Python

python - 使用 pdb 时如何忽略一行?

python - 在数据框的单个列上进行 Pandas 逻辑索引以分配值

python - 让 get-pip.py 安装特定 pip 版本的任何技巧?

python - 一种管道可以同时适应文本和分类特征

python - 将 '?' 添加到列表中每个字符串的末尾

python - 文件内容没有预期的那么长

python - 元音索引 : Python error "' in <string >' requires string as left operand, not int"

python - 当我们调用一个类时会发生什么?

python - 得到一个似乎没有多大意义的错误。