[pylucene-dev] PyLucene thread-safe?

Andreas Jung lists at andreas-jung.com
Mon Jun 28 10:12:03 PDT 2004



--On Montag, 28. Juni 2004 10:05 Uhr -0700 Andi Vajda 
<vajda at osafoundation.org> wrote:

> I don't know much about Zope but I imagine the worker threads are being
> created somewhere. That is where the run method of these threads needs to
> be wrapped by a call to attachCurrentThread.
>

The code to start the thread worker pool is this:

class ZRendevous:
    """Worker thread pool

    For better or worse, we hide locking sementics from the worker
    threads.  The worker threads do no locking.
    """

    def __init__(self, n=1):
        sync = thread.allocate_lock()
        self._acquire = sync.acquire
        self._release = sync.release
        pool = []
        self._lists = (
            pool, # Collection of locks representing threads are not
                  # waiting for work to do
            [],   # Request queue
            [],   # Pool of locks representing threads that are
                  # waiting (ready) for work to do.
            )

        self._acquire() # callers will block
        try:
            while n > 0:
                l = thread.allocate_lock()
                l.acquire()
                pool.append(l)
                thread.start_new_thread(ZServerPublisher,
                                        (self.accept,))
                n = n-1
        finally:
            self._release() # let callers through now



The worker code in ZServerPublisher is the following:

class ZServerPublisher:
    def __init__(self, accept):
        from ZPublisher import publish_module
        while 1:
            try:
                name, request, response=accept()
                publish_module(
                    name,
                    request=request,
                    response=response)
            finally:
                response._finish()
                request=response=None

So Zope is using the "thread" module but PyLucence wants a threading.Thread 
instance. Do
you see any chance to achive that?

-aj






More information about the pylucene-dev mailing list