[pylucene-dev] pylucene and pylons

Andi Vajda vajda at osafoundation.org
Fri Apr 11 09:21:24 PDT 2008


On Apr 11, 2008, at 8:47, John Beaver <john.e.beaver at gmail.com> wrote:

> Hi, I'm trying to integrate PyLucene with a Pylons app, but I'm  
> having serious stability problems. Does anyone have experience with  
> this?
>
> Specifically, I have a single action which does the following:
>
> lucene.initVM(lucene.CLASSPATH)
> directory = FSDirectory.getDirectory(Globals.LUCENE_INDEX_PATH);
> searcher = IndexSearcher(directory)
> analyzer = StandardAnalyzer()
> query = QueryParser('terms', analyzer).parse(term)
> hits = searcher.search(query)
> ... process hits
>
> It works perfectly the first time I view the corresponding webpage,  
> but it reproducibly crashes the webserver (paster serve) the second  
> time I try, always while in the initVM() function.
>
> I've tried putting the initVM() call in middleware.py, and I've  
> tried using a global flag to make sure that initVM() is only called  
> once in the controller. Both seem to fail when a different thread  
> tries to access PyLucene functions.
>
> I'm assuming this is a threading issue, so I'm going to write some  
> code to ensure that everything happens within a single thread. But  
> does anyone have a simpler solution for getting this working within  
> Pylons?

initVM() should be called from the main thread. Calling it more than  
once, in recent versions, is a nop.

Any other thread requiring JVM access needs to first call  
env.attachCurrentThread() or the process will crash. See README for  
PyLucene and JCC for more info.

Andi..


>
> _______________________________________________
> pylucene-dev mailing list
> pylucene-dev at osafoundation.org
> http://lists.osafoundation.org/mailman/listinfo/pylucene-dev


More information about the pylucene-dev mailing list