When a Jython script is being debugged, it is normally launched by PyDev, and
PyDev can optionally create a debug session for the script. When DS-5 launches the
Jython script, however, this does not happen. This is not a problem, however, because
the script itself can register with the PyDev debugger after it is launched. To do this
in your script:
- Extend the import list for the script to import pydevd. If you are using a
second DS-5
instance to host the PyDev debugger, then add the following to the top of the DTSL
script:
import pydevd
If you are using another
Eclipse (non-DS-5) to host the PyDev debugger, then import the pydevd from that
Eclipse instance. Locate the pydev plugin pysrc
directory and add its path to the import path before importing pydevd. For example,
if the Eclipse is installed in C:\Users\john\eclipse, then the code would be as
follows:import sys;
sys.path.append(r'C:\Users\john\eclipse\plugins\org.python.pydev_2.7.4.2013051601\pysrc')
import pydevd
where
pydev_xyz
depends on the version of
pydev installed within Eclipse.
- Insert the following line at the location where you want the PyDev debugger to
gain control of the
script:
pydevd.settrace(stdoutToServer=True, stderrToServer=True)
This
causes a break into the debugger at that location, and redirects all standard output
from the script to the debugger console. This allows you to place print statements
into the script and see them in the debugger, whereas normally DS-5 would discard any such print
output. Good places to insert this statement are:
- In the constructor (
__init__
) for the DTSL configuration class.
- In the
optionValuesChanged
method.
The function documentation for the settrace
call in pydev 2.7.4 is as follows:
def settrace(host=None, stdoutToServer=False, stderrToServer=False, port=5678, suspend=True, trace_only_current_thread=True):
'''Sets the tracing function with the pydev debug function and initializes needed facilities.
@param host: the user may specify another host, if the debug server is not in the
same machine (default is the local host)
@param stdoutToServer: when this is true, the stdout is passed to the debug server
@param stderrToServer: when this is true, the stderr is passed to the debug server
so that they are printed in its console and not in this process console.
@param port: specifies which port to use for communicating with the server (note that
the server must be started in the same port).
@note: currently it's hard-coded at 5678 in the client
@param suspend: whether a breakpoint should be emulated as soon as this function
is called.
@param trace_only_current_thread: determines if only the current thread will be
traced or all future threads will also have the tracing enabled.
'''