是否可以在 PyDev 脚本中设置断点?

Is it possible to set breakpoints in PyDev Scripting?

我想在 PyDev script written in Jython 中设置一个断点。我尝试了各种配置:

(1) 在 Eclipse 编辑器中设置断点但没有任何反应。

(2 & 3) 通过在脚本中添加以下代码强制跟踪:

import template_helper

if False:
    py_context_type = org.python.pydev.editor.templates.PyContextType

def MyFunc(context):
    # option (2) - try pydevd with another eclipse session hosting debug server
    #import sys
    #sys.path.append(r"... pydev.core_6.3.3.201805051638\pysrc")
    #import pydevd; pydevd.settrace()

    # option (3) - try pdb
    import pdb; pdb.set_trace()
    return "some text"

template_helper.AddTemplateVariable(py_context_type, 'mysub', 'A desc', MyFunc)

尝试 pydevd(选项 2)只是崩溃,并在 error_log 中添加了一个异常:

Caused by: Traceback (most recent call last):
  File "...\org.python.pydev.jython_6.3.3.201805051638\jysrc\template_helper.py", line 20, in resolveAll
    ret = self._callable(context)
  File "...\pydev_scripts\src\pytemplate_local.py", line 12, in MyFunc
    import pydevd; pydevd.settrace(stdoutToServer=True, stderrToServer=True)
  File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\pydevd.py", line 1189, in settrace
    _locked_settrace(
  File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\pydevd.py", line 1295, in _locked_settrace
    debugger.set_tracing_for_untraced_contexts(ignore_frame=get_frame(), overwrite_prev_trace=overwrite_prev_trace)
  File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\pydevd.py", line 595, in set_tracing_for_untraced_contexts
    for frame in additional_info.iter_frames(t):
  File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\_pydevd_bundle\pydevd_additional_thread_info_regular.py", line 117, in iter_frames
    current_frames = _current_frames()
  File "...\org.python.pydev.core_6.3.3.201805051638\pysrc\_pydevd_bundle\pydevd_additional_thread_info_regular.py", line 26, in _current_frames
    as_array = thread_states.entrySet().toArray()
AttributeError: 'java.lang.ThreadLocal' object has no attribute 'entrySet'

尝试 vanilla pdb(选项 3)在 PyDev 脚本控制台中打印 (Pdb) 提示,但不能输入任何文本并进入交互模式,例如:

(Pdb) IOError: IOError(...nvalid',)
> ...\org.python.pydev.jython_6.3.3.201805051638\jysrc\template_helper.py(20)resolveAll()
-> ret = self._callable(context)
(Pdb) 

也许这是不可能的。有什么建议吗?

为了将来参考,我最终能够通过下载 jython 2.7.1 installer from maven 来调试脚本。然后我将这个 jython 安装到一个临时位置。备份与 pydev 捆绑的 jython 插件文件夹后,我将相关目录与 pydevd 包的副本一起复制并粘贴到 pydev jython 安装程序上。按照我上面的选项 (2) 中的描述设置断点后,我能够在单独的 Eclipse 实例中逐步调试。

感谢您在@FabioZadrozny 的评论中提供的帮助。