[Zope] thread-safe xml request client
Passin, Tom
tpassin@mitretek.org
Wed, 14 May 2003 15:26:34 -0400
[Scott Burton]
> So use time.sleep() to run the main app thread with a lock to=20
> change the
> variables? How would I spawn a thread that will let Zope continue with
> its threads? I guess I would like to know a little more about how Zope
> calls products and if the global interpreter lock locks all threads
> until a call is completed how do I stop that? I am not saving anything
> to the ZODB.
>=20
There are a couple of non-obvious things about using Python threads.
First of all, even using sleep(), the function that started the thread
will not return until the thread finishes. If it starts, say, five
threads, those five threads will go off and do their work but the caller
will not return until all five threads do.
Second, you cannot stop a thread before it wants to quit. So if you
want it to quit, you have to arange for it to check some kind of a
signal somewhere to tell it to do so. But if the thread is waiting on a
slow socket, it cannot do any such checking because sockets are
synchronous (although there is an asynchronous socket library out
there, I believe that Zope does not use it - hope someone can correct me
on that).
So using threads effectively is harder than it might seem.
Cheers,
Tom P