On Wednesday November 14 2007 3:28:29 pm Bill Janssen wrote:
> > If you meant to ask if there was another API to attach _another_ thread
> > to the VM from a given thread, the answer seems to be 'no'.
>
> That's what I was asking.  It means I have to subclass
> threading.Thread and add a before-method for run() (to make sure all
> my threads are Lucene-capable).  If I could call it from a different
> Python thread, I could call it from the thread which creates the new
> thread, before I call start() on the new thread.

Heh, I was thinking about this recently too & came up with much the same 
ideas.  The other option is to have your target func or subclass run() call 
attachCurrentThread before doing things, obviously.  Though this won't work 
if you're firing threads off willy-nilly.

If you're gong to be using this pretty widely and in code that may not be used 
with lucene, a variant of the monkeypatch function I wrote for gcj-PyLucene 
may be handy.  You'll want to replace PythonThread with BillThread and call 
it early in your app (ie, before `import threading`).

def monkeypatch():
    """
    Monkey patch standard library threading module to use PythonThread.

    This function replaces Python's threading.Thread class with this
    module's PythonThread class, an extension of threading.Thread that
    delegates the actual OS thread setup to libgcj.
    """

    threading.Thread=PythonThread
    threading._Timer.__bases__=(PythonThread,)

-- 
Peter Fein   ||   773-575-0694   ||   [EMAIL PROTECTED]
http://www.pobox.com/~pfein/   ||   PGP: 0xCCF6AE6B
irc: [EMAIL PROTECTED]   ||   jabber: [EMAIL PROTECTED]
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to