[ale] Re: Threading? (was: Re: [ale] C#)

Joseph A Knapka jknapka at earthlink.net
Thu Sep 26 17:27:20 EDT 2002


Michael D. Hirsch wrote:
 >

[A lot of good stuff about threading in general...]

> 
> Python only has user threads (I think--I'm no expert on this aspect of 
> python).  When a thread does I/O the threading library is pretty clever 
> and can time it out, but until it either times out or finishes, no 
> other thread in that process will proceed.  So in, say, a web server 
> like ZOPE, if there are a lot of connections there will be a lot of 
> threads blocking on I/O.  This will slow it down incredibly.  Also if 
> the threads have to pull data off the disk they will block on disk 
> access, again slowing it down.  For this reason ZOPE tries to cache all 
> it's objects in RAM.  It is quite possible to run out of RAM for this.  
> Also, until everything is in RAM there are lots of threads blocking on 
> disk access.
> 
> I think I read somewhere that python is trying to use kernel threads, 
> but I don't recall if that was in version 2.2, which is already 
> release, or in a future version.

Python does use kernel threads, and has for some time (possibly
since threads were originally implemented in Python, but I'm not
sure about that).

I/O operations don't block other threads in Python. There
*is* a deficiency (some would say) in CPython threads, in that
the Python virtual machine executes Python bytecode under
the Global Interpreter Lock. That means that only one thread
can execute Python bytecode at a time. However, native code
running under Python, including the I/O facilities and most
extension modules, releases the GIL so that other threads
can proceed. So Zope doesn't suffer any performance loss
due to the GIL. But it is the case that multiple threads
running Python bytecode can't take advantage of multiple
CPUs, which sucks IMO.

Note also that Jython (Python compiled to Java bytecode) uses
the Java threading facilities and does not have anything
like the GIL, so a Jython solution should be as fast as
a Java solution, and the code will be *way* prettier :-)

> I love python--I would say it is my favorite language--and I hope it 
> gets better threading support soon.

I think Guido is not much interested in losing the GIL.
The Stackless guys might, though.

Cheers,

-- Joe


---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list