While JPype obfuscates Java from the user, Java is front-and-center for the developer. When bugs or
implementation issues arise, The program will probably need to be debugged in Java. Yet, since
typical input is a Python script, the process of debugging is not as straightforward as it is for a
normal java application. That said, it’s also not too complex. The way to do it is to pass an
addition argument to the osprey.start()
function:
osprey.start(attachJvmDebugger=True)
This will enable the Java process to be attached to by a java debugger. Intellij IDEA has a nice one you
can use. When you pass this optional parameter to the start()
function, the script will pause
after the JVM starts and print a message telling you to attach a debugger. Once you hit enter, the
script will resume. If you have not attached a debugger or have attached a debugger but have not
set any breakpoints, the script runs without pause, as before. The process for attaching a debugger
in Intellij is as follows:
./gradlew pythonDevelop
so that the
python version of Osprey is the same as the java code you’re about to debug.attachJvmDebugger
argument set to True.python
.Your breakpoint should be hit and you should be on your way to debugging as normal in java land.