2

I am using Python to invoke many of my Java programs. Is it possible to use debug perspective for both Python and Java and trace the progress in both languages at the same time? Thanks

asked Sep 19, 2012 at 11:33
9
  • What environment do you have and what tools are you using for debugging? Commented Sep 19, 2012 at 11:41
  • Maybe using two different Eclipse instances (or Eclipse and Netbeans) with Java configured for remote debugging? Commented Sep 19, 2012 at 11:53
  • @Raffaele wouldn't you come across the problem of having different instances of the program running? if you are trying to debug in different IDE's (say one IDE invokes an object from java, that object isn't carried to the other IDE, because they are both different processes on a different memory buffer) as far as I know netbeans and eclipse aren't atomic with one another. Commented Sep 19, 2012 at 11:54
  • @Raffaele atomicity means all or nothing in concurrency or An atomic operation is an operation which is performed as a single unit of work without the possibility of interference from other operations. (its to do with how things synchronize with one another) Commented Sep 19, 2012 at 12:42
  • @Killrawr I know what atomic operations are, just can't figure out what you mean by "Netbeans and Eclipse are not atomic with one another" - BTW I posted a working example of my concept Commented Sep 19, 2012 at 13:18

2 Answers 2

3

I downloaded two different Eclipse, one for JavaSE and when for PyDev. A Python script starts a JVM in remote debugging mode, then the other Eclipse instance connects via remote debugging to this JVM. This way you are able to debug both Python and Java code, even if in two different IDEs (I don't know if this can be done in the same instance, ie if two debugging session can exist in the same Eclipse instance, however I don't care because I use different Eclipse instances for Python, Java, Scala, Android...)

Create the following Java program and export a runnable JAR, for example at the location /home/raffaele/hello.jar, and set a breakpoint at the line with System.out.println()

public class HelloWorld {
 public static void main(String[] args) {
 for (int i = 0; i < 10; i++)
 System.out.println(i);
 }
}

Create a Python script, add a breakpoint at line print i and hit Debug as Python script. The subprocess output should be redirected to the Eclipse console and you should see the message Listening for transport dt_socket at address: 8000

import subprocess
subprocess.call(["java", "-jar", "-Xdebug",
 "-Xrunjdwp:transport=dt_socket,address=8000,server=y",
 "/home/raffaele/hello.jar"])
for i in range(1, 10):
 print i

At this point, in the JavaSE Eclipse instance, create a Remote Debug configuration: Run> Debug Configuration, in the left column select Remote Java Application and in the right one choose a name, host localhost, transport socket port 8000. Hit Apply, then Debug. The Debug perspective in the JavaSE instance will be opened, and you'll see your code suspended at System.out.println. In the right pane, you can inspect local variable, for example i = 0. Hit Resume for 10 times and the PyDev instance will blink, because the Python breakpoint has been hit.

answered Sep 19, 2012 at 13:14
Sign up to request clarification or add additional context in comments.

Comments

0

I am using Python to invoke many of my Java programs. Is it possible to use debug perspective for both Python and Java and trace the progress in both languages at the same time? Thanks

Not that I know of (SO: CBT and Java on Eclipse Debug). You could try other debugging methods such as logging events with log4j (for your java exceptions and so on) or go about building an ant script with junit and pyunit unit testing techniques, and aim for good coverage.

Try this website Testing Java with Jython and PyUnit, I think this is what you are after.

JUnit, the unit test framework written by Erich Gamma and Kent Beck, is not the only alternative for unit testing in the Java environment. This article provides a simple demonstration on how to use Jython, PyUnit and Ant to unit test a Java project. To provide better elements of comparison, the example provided is the same as the one available in the JUnit distribution: MoneyTest.

This article assumes that the reader has some basic knowledge of unit testing, Java, Jython or Python and possibly Apache Ant. For more information about each of those technologies, see section Resources at the end of this article. (Burgaud, 2012)

Good luck!

answered Sep 19, 2012 at 11:41

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.