[pylucene-dev] Exceptions in PyLucene
Andi Vajda
vajda at osafoundation.org
Wed Apr 9 11:02:10 PDT 2008
On Wed, 9 Apr 2008, João Rodrigues wrote:
> Hello all, I'm wanting to build a script that, considering the RAM of the
> user, it either chooses to use a RAM directory or a FS one. However, the
> method I'm using right now is trying to create the JVM with 2g maxheap
> size, and if it fails, catching the exception, evaluating it, and if it is
> because of not enough RAM, reducing RAM to my application minimum required
> and creating an FS directory. Problem is, I can't understand how to catch
> the exception... can you give me a sample code? I've read that ou have
> implemented a class of lucene.JavaErrors, but I really can't see how it
> works...
I think your approach is flawed in several ways.
maxheap is just specifying an upper memory limit, the VM is not going to
attempt to allocate or reserve that much memory until it's actually
needed.
Instead, you could try to use the initialheap keyword with initVM() but that
doesn't work as expected either. If the VM cannot reserve that much memory
it doesn't exit gracefully. It sends a signal instead, killing the process.
If you experiment with this be sure to _also_ set a maxheap value that is
larger than the initialheap, otherwise you're going to get a different error
from the VM, also signalled by a crash.
It seems to me that when any error occurs at VM start up time that has to do
with errors in the arguments passed to it, it doesn't fail to start
gracefully with an error that Python can report. It simply kills the process
with a signal. I tried to set signal handlers for Python to handle the
signal but it looks like the signal sent by the VM is one of the signals
that can't be hooked (SIGKILL). I don't know how this behaves on Windows
either.
I also tried to see if there was a way to tell Java not to signal at all.
Following this in gdb, it seems that it's using a function called
JVM_RaiseSignal() to do its thing but I could not find any documentation
about it nor is it declared in the <jni.h> header file.
A better approach to your problem might be to check via Python - before
starting the VM - what kind of memory your system has and 'assume' that if
enough is reported, the VM will be able to use it if you give it to it via
the initialheap and maxheap keywords.
Andi..
More information about the pylucene-dev
mailing list