Thanks for the reply.
So it seems detachCurrentThread can be more harmful then beneficial.
because crash may occur on creating any lucene object
e.g. If I use doc = lucene.Document() in a thread without doc = None
And it may not always be possible to clean every object e.g.
if some exception is raised or some other function is called which communicates
error conditions via Exceptions.
e.g. see attached code.
I think I am pretty much stuck here and will have to abondon multiple threads :(
rgds
Anurag
----- Original Message ----
From: Andi Vajda <[EMAIL PROTECTED]>
To: [email protected]
Sent: Monday, 14 January, 2008 11:06:54 PM
Subject: Re: [pylucene-dev] detachCurrentThread crash
On Mon, 14 Jan 2008, anurag uniyal wrote:
> Is it expected to explicity remove any references to local/class variables
> in threads?
If you create threads faster than Python and Java can collect the objects
you leave lying around, then yes.
For instance, closing the store you're opening in every thread instead of
None'ing it out may have the same effect.
Andi..
Otherwise VM crashes. e.g.
-----------
import threading
import lucene
lucene.initVM(lucene.CLASSPATH)
def threadFunc():
lucene.getVMEnv().attachCurrentThread()
_store = lucene.FSDirectory.getDirectory("/tmp/index/", True)
#_store = None # set to None to avoid crash!
lucene.getVMEnv().detachCurrentThread()
def main():
t = threading.Thread(target=threadFunc)
t.start()
t.join()
main()
----
I need to call detachCurrentThread because I use threads heavily andI will soon
get out-of-memory error if didn't call detachCurrentThread.
rgds
Anurag
Save all your chat conversations. Find them online at
http://in.messenger.yahoo.com/webmessengerpromo.php
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev
Get the freedom to save as many mails as you wish. To know how, go to
http://help.yahoo.com/l/in/yahoo/mail/yahoomail/tools/tools-08.htmlimport threading
import lucene
lucene.initVM(lucene.CLASSPATH)
class MyThread(threading.Thread):
def __init__(self):
"""
pass the method to call, docs to process and whether it is a commit
"""
threading.Thread.__init__(self)
def run(self):
lucene.getVMEnv().attachCurrentThread()
try:
self.func()
except Exception,e:
print e
lucene.getVMEnv().detachCurrentThread()
def func(self):
doc = lucene.Document()
raise Exception("Lets Crash!")
def main():
t = MyThread()
t.start()
t.join()
main()
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev