【问题标题】:PyDev breaking at built-in breakpointPyDev 在内置断点处中断
【发布时间】:2021-03-03 08:45:05
【问题描述】:

PyDev 在 Python 代码中的内置断点处中断,并出现以下错误。

warning: Debugger speedups using cython not found. Run '"/Users/Work/opt/anaconda3/envs/ch_dev37/bin/python" "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/setup_cython.py" build_ext --inplace' to build.
Could not connect to 127.0.0.1: 5678
Traceback (most recent call last):
  File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/_pydevd_bundle/pydevd_comm.py", line 462, in start_client
    s.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused
Traceback (most recent call last):
  File "/Volumes/GoogleDrive/My Drive/free_energy_data/write_energies.py", line 111, in <module>
    write_gases, write_adsorbates, verbose)
  File "/Users/Work/opt/dev/gits/CatHub/cathub/catmap_interface.py", line 31, in write_energies
    breakpoint()
  File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/pydev_sitecustomize/sitecustomize.py", line 74, in custom_sitecustomize_breakpointhook
    pydevd.settrace(*args, **kwargs)
  File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/pydevd.py", line 2623, in settrace
    notify_stdin=notify_stdin,
  File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/pydevd.py", line 2688, in _locked_settrace
    py_db.connect(host, port)  # Note: connect can raise error.
  File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/pydevd.py", line 1262, in connect
    s = start_client(host, port)
  File "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.1.202011071328/pysrc/_pydevd_bundle/pydevd_comm.py", line 462, in start_client
    s.connect((host, port))
ConnectionRefusedError: [Errno 61] Connection refused

我正在使用 GUI 中的“运行”选项(附件图像中的播放按钮)运行 Python 代码。

这种行为令人惊讶,因为正如 release notes 所说,自 PyDev 的早期版本 (v6.5.0) 以来就已支持 breakpoint() 内置函数。到目前为止,我已经使用import pdb; pdb.set_trace() 作为断点,它仍然运行良好。内置的 breakpoint() 在终端中的 PyDev 之外运行良好,没有任何问题。

其他详情:

Python Version: 3.7.8
Eclipse Version: 2020-09 (4.17.0)
PyDev Version: 8.0.1
Device: MacBook Pro
OS: macOS Big Sur 11.0.1

【问题讨论】:

  • 你试过run '"/Users/Work/opt/anaconda3/envs/ch_dev37/bin/python" "/Applications/Eclipse.app/Contents/Eclipse/plugins/org.python.pydev.core_8.0.0.202009061309/pysrc/setup_cython.py" build_ext --inplace' to build吗?
  • 不确定我是否理解正确。刚刚更新了关于我如何运行代码的帖子。我只是使用“运行”按钮(GUI 中的播放按钮)使用“Python 运行”选项。
  • 好的,所以你的答案是否定的。该错误准确地告诉您必须在终端/命令行中运行什么命令才能解决该问题。所以我会尝试一下,然后看看问题是否仍然存在。
  • 当我使用eclipse gui('播放'按钮)运行时,使用的python解释器确实是“/Users/Work/opt/anaconda3/envs/ch_dev37/bin/python”。我使用 IDE 通过 GUI 运行脚本,而不是在我输入命令来执行脚本的模式下使用它。

标签: python python-3.x eclipse pydev


【解决方案1】:

在这种情况下,breakpoint() 尝试使用Remote Debugger 连接到 IDE,而ConnectionRefusedError: [Errno 61] Connection refused 表示您尚未在客户端启动远程调试器。

因此,要解决此问题,请在运行之前在客户端启动调试服务器(然后在启动时它将在没有附加调试器的情况下运行,直到达到breakpoint())。

有关如何在客户端启动远程调试器的信息,请参阅:https://www.pydev.org/manual_adv_remote_debugger.html

【讨论】:

  • 谢谢!当我在启动调试服务器后运行代码时,代码现在一直执行到 breakpoint() 并将Debug Server at port: 5678 打印到控制台。控件没有返回给用户,我也无法继续执行。如何在 PyDev 中使用 import pdb; pdb.set_trace() 尽可能利用交互功能?或者这是一个限制?
  • 此时您应该能够使用 IDE 中的调试器...为什么在这种情况下您要使用 pdb 而不是实际的 PyDev 调试器?
猜你喜欢
  • 2010-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-18
  • 2011-11-19
相关资源
最近更新 更多