processing limitation in Python

Dave Hansen iddw at hotmail.com
Tue Feb 14 12:39:15 EST 2006


On 14 Feb 2006 08:42:38 -0800 in comp.lang.python, "pdr14 at comcast.net"
<pdr14 at comcast.net> wrote:

>If I un-comment any line in this program below the line where I
>commented " all OK up to this point " This program locks up my
>computer.

Hmm.  Ctrl-C gets me out just fine.  In Idle, at least.

>
>Windows task manager will show "Not Responding" for Python in the
>Applications tab and in the Performance tabe the CPU usage will be
>locked at %100.

Well sure.  It's pretty busy code.

>
>I've experienced the same problem on 2 different computers, one running
>2000 pro. the other running XP home eddition.  both computers run
>Python 2.4.2
>
>I'm just wondering if any one else has noticed any problems with
>working with large numbers in Python ind if there is anything that can
>work around this issue.

Try running with the changes I've made below, and see if that tells
you anything.

def factor(n):
    d = 2
    pctr = 0
    factors = [ ]
    while n > 1:
        if n % d == 0:
            factors.append(d)
            n = n/d
        else:
            d = d + 1
            pctr += 1
            if pctr >= 1000000:
                print "So Far: " + str(factors)
                pctr = 0
    print factors
factor (12)
factor (123)
factor (1234)
factor (12345)
factor (123456)
factor (1234567)
factor (12345678)
factor (123456789)
factor (1234567898)
factor (12345678987)
factor (123456789876)
factor (1234567898765)       # all OK up to this point
factor (12345678987654)    # locks up computer if I run this line
#factor (123456789876543)
#factor (1234567898765432)
#factor (12345678987654321)


Hint: 2057613164609L is a Really Big Number (tm).  If it's prime (I
don't know if it is or not), it will take more than 46 days on my
computer to figure that out.  Did you wait that long?

Regards,
                                        -=Dave

-- 
Change is inevitable, progress is not.



More information about the Python-list mailing list