Home | About | Sematext search-lucene.com search-hadoop.com
 Search Lucene and all its subprojects:

Switch to Threaded View
PyLucene, mail # dev - call python from java - what strategy do you use?


Copy link to this message
-
Re: call python from java - what strategy do you use?
Roman Chyla 2011-01-12, 13:41
Hi Andi, all,

I tried to implement the PythonVM wrapping on Mac 10.6, with JDK
1.6.22, jcc is freshly built, in shared mode, v. 2.6. The python is
the standard Python distributed with MacOsX

When I try to run the java, it throws an error when it gets to:

static {
        System.loadLibrary("jcc");
    }

I am getting this error:

Exception in thread "main" java.lang.UnsatisfiedLinkError:
/Library/Python/2.6/site-packages/JCC-2.6-py2.6-macosx-10.6-universal.egg/libjcc.dylib:
 Symbol not found: _PyExc_RuntimeError   Referenced from:
/Library/Python/2.6/site-packages/JCC-2.6-py2.6-macosx-10.6-universal.egg/libjcc.dylib
  Expected in: flat namespace  in
/Library/Python/2.6/site-packages/JCC-2.6-py2.6-macosx-10.6-universal.egg/libjcc.dylib
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1823)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1746)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at org.apache.jcc.PythonVM.<clinit>(PythonVM.java:23)
at rca.solr.JettyRunnerPythonVM.start(JettyRunnerPythonVM.java:53)
at rca.solr.JettyRunnerPythonVM.main(JettyRunnerPythonVM.java:139)
MacBeth:JCC-2.6-py2.6-macosx-10.6-universal.egg rca$ nm libjcc.dylib | grep Exc
                 U _PyExc_RuntimeError
                 U _PyExc_TypeError
                 U _PyExc_ValueError
0000000000003442 T __ZNK6JCCEnv15reportExceptionEv
00000000000021f0 T __ZNK6JCCEnv23getPythonExceptionClassEv
Any pointers what I could do wrong? Note, I haven't built any emql.egg
yet, I just run my java program and try to start PythonVM() and see if
that works.

Thanks,

  roman

On Wed, Jan 12, 2011 at 11:05 AM, Roman Chyla <[EMAIL PROTECTED]> wrote:
> Hi Andi,
>
> I think I will give it a try, if only because I am curious. Please see
> one remaining question below.
>
>
> On Tue, Jan 11, 2011 at 10:37 PM, Andi Vajda <[EMAIL PROTECTED]> wrote:
>>
>>
>> On Tue, 11 Jan 2011, Roman Chyla wrote:
>>
>>> Hi Andy,
>>>
>>> This is much more than I could have hoped! Just yesterday, I was
>>> looking for ways how to embed Python VM in Jetty, as that would be
>>> more natural, but found only jepp.sourceforge.net and off-putting was
>>> the necessity to compile it against the newly built python. I could
>>> not want it from the guys who may need my extension. And I realize
>>> only now, that embedding Python in Java is even documented on the
>>> website, but honestly i would not know how to do it without your
>>> detailed examples.
>>>
>>> Now to the questions, I apologize, some of them or all must seem very
>>> stupid to you
>>>
>>> - pylucene is used on many platforms and with jcc always worked as
>>> expected (i love it!), but is it as reliable in the opposite
>>> direction? The PythonVM.java loads "jcc" library, so I wonder if in
>>> principle there is any difference in the directionality - but I am not
>>> sure. To rephrase my convoluted question: would you expect this
>>> wrapping be as reliable as wrapping java inside python is now?
>>
>> I've been using this for over two years, in production.
>> My main worry was memory leaks because a server process is expected to stay
>> up and running for weeks at a time and it's been very stable on that front
>> too. Of course, when there is a bug somewhere that causes your Python VM to
>> crash, the entire server crashes. Just like when the JVM crashes (which is
>> normally rare). In other words, this isn't any less reliable than a
>> standalone Python VM process. It can be tricky, but is possible, to run gdb,
>> pdb and jdb together to step through the three languages involved, python,
>> java and C++. I've had to do this a few times but not in a long time.
>>
>>> - in the past, i built jcc libraries on one host and distributed them on
>>> various machines. As long the family OS and the python main version were the
>>> same, it worked on Win/Lin/Mac just fine. As far as I can tell, this does