python threads

Aahz Maruch aahz at panix.com
Fri Dec 21 10:44:20 EST 2001


In article <96c7f32.0112210450.174f6914 at posting.google.com>,
curt finch <curt at journyx.com> wrote:
>
>My understanding is that python's current threads implementation
>does not really allow for this in the sense that only one thread
>can be running at a time, regardless of the number of chips on
>the machine, and additionally that the threads cannot really
>interrupt each other and still maintain correct state.
>
>Is that all correct?

Oleg and Michael are wrong: the answer is "sort of yes and sort of no".

It is true that threads running pure Python code can only run one at a
time.  However, as soon as a thread makes a function call into an
extension, the extension can release the Global Interpreter Lock (GIL).
All of the standard I/O functions (including sockets), for example, are
coded this way, so that running a threaded app with a lot of I/O
typically gets a heavy speed boost.

If you want to do computational threading, there's no reason why you
can't write an extension that also releases the GIL.  The reason so
little of that has been done is that computational threading only makes
sense under SMP; the GIL provides superior performance with a single
CPU.

It *is* true that Python threads running Python code cannot interrupt
each other preemptively.

For more info, see http://starship.python.net/crew/aahz/
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Hugs and backrubs -- I break Rule 6                 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista   

Tenth Virtual Anniversary: 10 days and counting



More information about the Python-list mailing list