I would like to set a breakpoint in a PyDev script written in Jython. I've tried various configurations:
(1) Setting a breakpoint in the Eclipse editor but nothing happens.
(2 & 3) Forcing a trace by adding following code into the script:
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)
Trying pydevd (option 2) just crashes with an exception added to error_log along lines of:
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'
Trying vanilla pdb (option 3) prints the (Pdb) prompt in the PyDev Scripting console but one can't enter any text and go into interactive mode, eg:
(Pdb) IOError: IOError(...nvalid',)
> ...\org.python.pydev.jython_6.3.3.201805051638\jysrc\template_helper.py(20)resolveAll()
-> ret = self._callable(context)
(Pdb)
Perhaps it's not possible. Any suggestions?
For future reference, I was eventually able to debug scripts by downloading jython 2.7.1 installer from maven. I then installed this jython to a temporary location. After backing up the jython plugin folder bundled with pydev, I copied and pasted the relevant directories over the pydev jython installer along with a copy of pydevd package. I was able to step through debug in separate instance of Eclipse after setting a breakpoint as described in my Option (2) above.
Thanks for your help in the comments @FabioZadrozny.