On Sat, 17 May 2008, Roopesh wrote:

Is it OK if two threads simultaneously accesses same instance of index
modifier and work with it? One thread is calling add documents to the index
and other thread is optimizing the index.

I don't know. That is a great question for [EMAIL PROTECTED] where all general Lucene usage questions are much better answered. Still, see below for more about threads and PyLucene.

To be more specific, in my project, I have two threads runnning. One thread
indexes the mails and another thread optimizes the index periodically. Both
are using the same Indexer instance which is a singleton. Inside the Indexer
class I have created an IndexModifier object, and that IndexModifier object
is used for indexing all the documents. (i.e., IndexModifier  object will be
created once when the Indexer class is created). And I am calling close() on
IndexModifier only when the sytem halts.

When the scheduler call the optimize() on the IndexModifier after an
interval of time (I am using the same instance of IndexModifier), the
following exception occurs:

(<class 'PyLucene.JavaError'>, JavaError(<Throwable:
u'java.lang.NullPointerException'>,), <traceback object at
0x02D7E440>)

You appear to be using the GCJ flavor or PyLucene. This has been deprecated for a while and replaced by the JCC flavor of PyLucene [1][2] which resolved a lot of random crasher issues (such as spurious NullPointerException exceptions) and is easier to use with threads. In particular, the call to attachCurrentThread() works. See [3] for more information about threading and JCC PyLucene.

PS: This is a turbogears project and I modified CherryPy to use
PyLucene.PythonThread instead of threading.Thread.

No need to play this trick with JCC PyLucene. Just be sure the thread calls attachCurrentThread() before making its first Java VM call.

Andi..

[1] http://pylucene.osafoundation.org/
[2] http://svn.osafoundation.org/pylucene/trunk/jcc/jcc/README
[3] http://svn.osafoundation.org/pylucene/trunk/jcc/README
_______________________________________________
pylucene-dev mailing list
pylucene-dev@osafoundation.org
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to