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
2 Answers 2
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.
Comments
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!
all or nothingin concurrency orAn 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)