[Zope-dev] is threading in zope useful ?

Tim Peters tim at zope.com
Tue Apr 27 20:43:11 EDT 2004


[sathya]
> I read somewhere that each zope thread acquires the global python
> interpreter lock before processing a request and until it releases it
> the other zope threads are essentially locked out.

The Python GIL (global interpreter lock) affects all code written in Python:
only one thread at a time can interpret Python bytecodes in a given process.
That's true in or out of Zope.

> Does that mean zope threads are eventually serialized and there are no
> benefits to be gained from concurrent execution ?

No.  The GIL effectively serializes threads doing pure computation in
Python, but many pieces of the Python implementation release the GIL around
calls to known-threadsafe C libraries.  The most important examples of that
are I/O, of many kinds.  For example, if a Python thread opens a socket, the
GIL is released around the C-level code that does the low-level socket open,
which allows other Python threads to proceed in parallel (of course the
thread that does the C-level socket open waits for the latter to finish; it
reacquires the GIL after the socket operation is complete and it's ready to
go back to interpreting Python bytecodes).  Because Zope does a lot of
network I/O, this form of parallelism can be very useful for it.




More information about the Zope-Dev mailing list