[Zope] thread-safe xml request client

Scott Burton scott@posplugin.com
Tue, 13 May 2003 12:29:35 -0700


I am writing a product in Zope 2.6 that sends xml requests to servers over
SSL. There are a few questions I have about the whole thread-safe issue
after reading http://www.zope.org/Documentation/How-To/ThreadSafety as well
as some other issues that are coming up.

I realized a few parts of my product are mutable so I wrapped those methods
in a thread as such:
lock = Lock()
class HTTPSRequester(SimpleItemWithProperties, Thread):
    def __init__(self):
        Thread.__init__(self)

"mutable method"
def run(self):
    lock.acquire()
    self.fetch()
    lock.release()


where fetch() is the method with mutable data.

Here are my questions regarding this setup...
1. Is this product actually considered thread-safe now?
2. The fetch method makes a https socket connection using httplib. The first
time it runs when zope is restarted it takes a VERY long time to make the
socket connection(like 20 -30 seconds) and usually returns an empty string
response from the server. The processor utilization goes up to 100% the
entire time. However, the second request takes about 1-2 seconds and returns
the correct info. I have no idea why it does this and would really like to
know why.
3. Is there any way I can create a thread or process that has all of the
modules I use opened and ready to use. I figure this might eliminate some
overhead on loading all of the modules per execution.
4. I have also noticed that when a user calls this product, Zope will stop
responding until the response is returned. I would like to have the product
be able to handle multiple simultaneous requests at once.

If anyone has dealt with a similar product I would very much appreciate your
input.

Thanks,
Scott