Threading question

David Lees debl at
Fri May 4 00:40:48 EDT 2001

I am struggling to improve the performance of some python code that has
2 threads and runs on a dual processor linux (redhat 7.0) box.  I am
using Python 2.1 and can not seem to get the cpu utilization up above
40% for each processor.  Here is a simple example that shows the essence
of the problem.  This is my first try at dual processor code and the
performance indicates I am doing something wrong.  The thing that really
seems strange and makes me wonder if the problem is python's
implementation of threads or something wierd in RedHat 7.0 linux, is
that when I run as a single tread I see 'top' flipping back and forth
between the 2 cpus, utilizing each at 99% and the other at 0.  Any
advice is welcome.

Thanks in advance.

david lees

def load(n):
    for i in range(n):
        sum = sum+math.sqrt(i)**3.5 #junk that loads the cpu

if __name__=='__main__':


    print 'Threads started'

More information about the Python-list mailing list