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

时间:2018-05-26 13:35:03

标签: debugging jython pydev

我想在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 Scripting控制台中打印(Pdb)提示,但是无法输入任何文本并进入交互模式,例如:

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

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

1 个答案:

答案 0 :(得分:0)

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

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