Project

Profile

Help

python kernel crash on second run, JNI_CreateJavaVM() failed with result: -5

Added by Rick Labs 5 months ago

New to Saxon, compiling, cross compiling, Jet, cython, etc. Working in Python with some knowledge of xml.

Installed Saxon/C on Win64 along with Visual Tools for compiling, SDK, run times. Fairly sure that all went as intended, but having trouble running the Saxon/C Python sample scripts. On the python side running current (as of 3/2021) python, Spyder IDE, and mini Anaconda (python environment/package manager, installer).

Here is simple code that runs once, then on the second run crashes the python kernel:

import saxonc

with saxonc.PySaxonProcessor(license=False) as proc:
   print(dir(proc))  #shows proc is running fine on first run

#tying to get this program to exit clean so it will run again
proc.release()
proc=None
del proc

Result on second run. Looks like something was left behind? "No such comm" an obsolete pointer?

JNI_CreateJavaVM() failed with result: -5
[SpyderKernelApp] WARNING | No such comm: 21e8428796eb11eb804c001a7dda7113

Replies (3)

Please register to reply

RE: python kernel crash on second run, JNI_CreateJavaVM() failed with result: -5 - Added by O'Neil Delpratt 5 months ago

Rick Labs wrote:

import saxonc

with saxonc.PySaxonProcessor(license=False) as proc:
   print(dir(proc))  #shows proc is running fine on first run

#tying to get this program to exit clean so it will run again
proc.release()
proc=None
del proc

Here you are using the PySaxonProcessor as a python context manager (i.e. using the with keyword), which means the context managers the resources. Hence the release() function is called automatically at the end. No need to explicitly call it as calling it twice in the program will cause a crash.

I also think there is no need to call del proc too.

RE: python kernel crash on second run, JNI_CreateJavaVM() failed with result: -5 - Added by Michael Kay 5 months ago

Also note that it's best to reuse the Processor object wherever possible: creating a new processor and releasing it on every transformation is very expensive.

RE: python kernel crash on second run, JNI_CreateJavaVM() failed with result: -5 - Added by Rick Labs 5 months ago

Thanks very much for the replies. I'm not yet to an intermediate level with Python, so much to learn especially details around OS memory allocation, paging, garbage collection, etc. Still, the following behavior seems odd, so I want to confirm its completely normal with python/saxonc:

import saxonc

with saxonc.PySaxonProcessor(license=False) as proc:
   print(dir(proc))
print('done')

Presumably, just before the print('done') line runs, the "with block" has been completed, and any clean up code related to that with statement has run. (release is automatic?)

From a fresh kernel start, above runs fine the first time. Run it again and get RE: python kernel crash on second run, JNI_CreateJavaVM() failed with result: -5

Reload the python kernel for a fresh start.

Run above, get normal output.
Run dir() from the console,  'proc' and  'saxonc' are included
Run %reset from the console
Run dir() from the console again. Confirm 'proc' and 'saxonc' are no longer included. 
Run above program again, get the same error as above.

Would have expected the with statement to have called clean up code on exit from the block, and would expect %reset from the console to clear things out in any case?

Very much understand in production programs you want to load proc only once and reuse it over and over for all XSLT work vs. constant loading/unloading. But not understanding the above behavior?

    (1-3/3)

    Please register to reply