[Tutor] Threading in Python

Kent Johnson kent37 at tds.net
Thu Sep 20 04:19:25 CEST 2007


James wrote:
> Hi.  :)
> 
> I have a question regarding threading in Python.  I'm trying to write  
> a wrapper script in Python that will spin off multiple (lots!) of  
> instances of an I/O benchmark/testing utility.  I'm very interested  
> in doing this in Python, but am unsure if this is a good idea.  I  
> thought I read somewhere online that because of the way Python was  
> written, even if I spun off (forked off?) multiple instances of a  
> program, all those child processes would be restricted to one CPU.   
> Is this true?

Python *threads* are limited to a single CPU, or at least they will not 
run faster on multiple CPUs. I don't think there is any such restriction 
for forked processes.

> I'm not sure if the utility I'm forking is CPU-intensive; it may very  
> well be.  Does Python indeed have this limitation?

I would think an I/O benchmark is more likely to be I/O bound...

> Also, should I be using os.fork() for this kind of program?

There is a fair amount of activity these days around making Python 
friendly to multi-processing. See
http://wiki.python.org/moin/ParallelProcessing

Kent


More information about the Tutor mailing list