Jython スクリプトがデバッグされる場合は通常、PyDev によって起動され、PyDev ではオプションでスクリプトのデバッグセッションを作成できます。ただし、DS-5 で Jython スクリプトが起動されると、この状況は異なります。これは、スクリプト自体を起動後に PyDev デバッガに登録できるため、問題ではありません。スクリプトでこれを行うには、以下の手順を実行します。
- スクリプトのインポートリストを拡大して pydevd をインポートします。2 つ目の DS-5 インスタンスを使用して PyDev デバッガをホストする場合は、以下を DTSL スクリプトの一番上に追加します。
import pydevd
別の Eclipse(DS-5 以外)を使用して PyDev デバッガをホストする場合は、その Eclipse インスタンスから pydevd をインポートします。pydev プラグイン pysrc ディレクトリを検索し、pydevd をインポートする前にパスをインポートパスに追加します。例えば、Eclipse が C:\Users\john\eclipse にインストールされている場合は、コードは次のようになります。import sys;
sys.path.append(r'C:\Users\john\eclipse\plugins\org.python.pydev_2.7.4.2013051601\pysrc')
import pydevd
ここで、pydev_xyz
は Eclipse 内にインストールされている pydev のバージョンによって異なります。
- PyDev デバッガでスクリプトを制御する場所に次の行を挿入します。
pydevd.settrace(stdoutToServer=True, stderrToServer=True)
こうすると、その場所でデバッガに分割され、スクリプトからのすべての標準出力がデバッガコンソールに転送されます。これにより、print ステートメントをスクリプトに配置してデバッガで表示できますが、通常、DS-5 によりそのような print 出力は破棄されます。このステートメントを挿入する最適な場所は、次のとおりです。
- DTSL コンフィギュレーションクラスのコンストラクタ(
__init__
)。
-
optionValuesChanged
メソッド。
pydev 2.7.4 での settrace
呼び出しの関数ドキュメントは、次のとおりです。
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.
'''