Jython Remote debug

jythonIt is all empty in the office this days. Most Swedes went for summer vacation. So I am not very busy and can spend some time to play technology.

There are few ways to debug a problem.

  • print information to debug file, then analyze the debug file. Some problem only can use this way to locate. For example, logic issues will only happen when system running in a high pressure.
  • debug trace, check variable values. It is specially useful when doing logic debug. There are few ways to drive debug trace, unit test, remote debug. Unit test is much easier then remote debug, if possible I will unit test but not remote debug.
  • dump memory. It is used mostly for memory issue analyzation.

Download Juno from eclipse web sitedownload Juno
I could not manage to install PyDev on line. So use office install instead. download pydev

there are few articles found on google about how to remote debug.

I only tried PyDev way. The step is the same as described in the article. I just write small example to drive it and got a small tip in pydev.

The way I wanna try is invoke Jython program from Java. And then I set break point either in java or Jython. A simple JUNIT test case is used to drive it.

@Test
public void test() {
    Properties props = new Properties();
    
    // The following information can use simple program
    // run an print it. 
    // print(os.environ['PYTHONPATH'])
    props.setProperty("python.path",
        "C:\\jython2.5.2\\eclipse\\plugins\\org.python.pydev_2.6.0.2012062818\\pysrc");
    PythonInterpreter.initialize(System.getProperties(), props,
                     new String[] {""});
    
    PythonInterpreter interp = new PythonInterpreter();
    interp.execfile(this.getClass().getResourceAsStream("whatever.py"));
    
    // It is just for test after jython execution, 
    // the break point still can back to here
    assertTrue(true);
}
# debug.py
enabledModules = ['debug', 'whatever']

def remote_debugable_if_enabled(name):    
    import os
    import pydevd

    if name in enabledModules:
        pydevd.settrace(stdoutToServer=True, stderrToServer = True)
    
    return

if __name__ == '__main__':
    remote_debugable_if_enabled('debug');

Then add following two lines to every files which possibly need remote debug.

import debug
debug.remote_debugable_if_enabled(__name__)

Modify debug.py if wanna enable debug, and then that file need be reloaded.

Tip: If PyDev always locate to a wrong file when you want remote debug more then one file. Try this Window->Preference->Pydev->Debug->Source Locator, clear all.

Your email will never published nor shared. Required fields are marked *...

Type your comment out: