5

I am writing Jython scripts in files and then calling them using Java, is there a way to debug those scripts?

asked Mar 8, 2012 at 10:36

3 Answers 3

4

Yes, you should be able to do that using a remote debugger (if you're using PyDev, take a look at: http://pydev.org/manual_adv_remote_debugger.html).

If you went the other way around (and launched your program with the entry point as a Jython program which called java code), you should use the java remote debugger instead (the trick is that the language which you didn't launch directly must be remote debugged).

answered Mar 12, 2012 at 4:14
Sign up to request clarification or add additional context in comments.

4 Comments

Will this work with Jython running from Java? String scriptSource = "import sys\n" + "sys.path.append('C:/tools/pydevd/pydevd280')\n" + "import pydevd\n" + "pydevd.settrace('localhost', port=5678, suspend=True)\n" + "name = 'abcd'"; ScriptEngine engine = manager.getEngineByName("python"); engine.eval(scriptSource); It briefly connects but do not pause and scripts continues running. Is there any mapping needed here? Since the script running from java is not based on a file
If the code is all in memory, then no (because although the debugger can start, it cannot find the source code to present to you).
I was wondering can we add something like the filename or path like a comment in the beginning sourcepath = ... which can tell the debugger which file to map it to or open a new window with script source in ide from server and debug that
As a note, it could be possible to add that support (in fact, in newer versions of the debugger we even show a disassemble of the bytecode if no source is available, but the main issue is that jython is no longer a target for the debugger and the existing version doesn't have that support -- it'd not be impossible to revive that version in a branch and improve it though, but that requires someone willing to take the effort and implement it).
2

You can use Eclipse and pydev ( http://pydev.org/ ) and use the debugger in pydev

answered Mar 9, 2012 at 14:15

1 Comment

I think OP's question was referring to debugging a Jython script once it's been invoked from within a Java program, which I'm not sure how to do, but I think that debugging the script on its own from Eclipse/PyDev is probably the best option. If the Jython script is taking parameters from the Java program, then perhaps halt the Java program whenever it's about to call the script, observe the values it was about to pass, and then fire up PyDev and debug it using the observed values. So in that sense, this is the correct answer.
0

You can log to stdout and/or stderr and the collect that on the java side and logging it out again.

answered Mar 8, 2012 at 10:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.