Threading in Python

Peter Hansen peter at engcorp.com
Fri Jul 27 02:34:43 EDT 2001


Andy wrote:
> 
> There seems to be a lot of (arguably) radical changes
> going on in the Python syntax/grammar/language, perhaps
> the direction should be towards improving the internals
> first?
> 
> One thing Java has which Python lacks is transparent
> support for multi-cpu threading.  Python has threads,
> but I believe it is internally implemented and has
> been shown not to take advantage of an SMP machine.

I'm not an expert on SMP.  In fact, I know next to 
nothing about SMP.  (But ignorance never stopped anyone 
from posting an answer on Usenet. :-)

I'm quite sure Python threads will take advantage
of whatever the native threads take advantage of,
since Python threads are *not* "internally implemented"
quite like you probably imagine.  On an OS and
platform with SMP support, different Python threads
probably execute on different CPUs.

Even so, you are probably right about there
being no advantage with multiple CPUs.  The reason,
however, would be the "global interpreter lock", 
which is a feature of the interpreter core which 
protects against the usual thread safety problems.

I haven't done enough work down at that level yet
to be able to answer the question "could Python
readily be changed to reduce the negative impact 
of the global interpreter lock on multithreaded
performance?"

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list