Python Crashes During Infinite Loops

A forum for general discussion of the Python programming language.

Python Crashes During Infinite Loops

Postby TotalHenshin » Sun Jul 06, 2014 5:34 pm


I'm running Python 2.5.4 as that's what's being mandated for a class I'm taking. I believe the title is pretty self-explanatory. Whenever I run a program in the IDLE editor that has an infinite loop, the shell and editor crash (instead of simply letting me hit CTRL+C to interrupt it). The easiest example would be something like the following:

Code: Select all
x = 5
y = 2
while x > 4:
    y += 1

print y

Very basic, but you can obviously think of any while loop that may never terminate. It's just a major hassle if I run a program that has an infinite loop and have to force close the shell and editor. Interestingly though, if I run a program such as this:

Code: Select all
x = 0.5
epsilon = 0.01
numGuesses = 0
low = 0.0
high = x
ans = (high + low)/2.0
while abs(ans**2 - x) >= epsilon and ans <= x:
    print low, high, ans
    numGuesses += 1
    if ans**2 < x:
        low = ans
        high = ans
    ans = (high + low)/2.0
print 'numGuesses =', numGuesses
print ans, 'is close to square root of', x

As you may have noticed this will cause an infinite loop because the square root of 0.5 is outside of the range given. But if I have the print command on line 8, it will print "0.5 0.5 0.5" on the shell forever (which I can interrupt). But if I remove that line, it crashes.

Is it a problem with my PC? I have:

Windows 7 Home Premium
x64-based PC
AMD FX(tm)-4100 Quad-Core Processor, 3600 Mhz, 2 Cores, 4 Logical Processors

Please let me know if you need any more info on my PC or otherwise. I'd greatly appreciate help on this.
Last edited by metulburr on Sun Jul 06, 2014 5:48 pm, edited 1 time in total.
Reason: locked post, added code tags
Posts: 1
Joined: Sun Jul 06, 2014 5:09 pm

Re: Python Crashes During Infinite Loops

Postby stranac » Sun Jul 06, 2014 7:25 pm

IDLE sucks.
Just get a decent text editor and run your programs from a terminal, and you'll be fine.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1790
Joined: Thu Feb 07, 2013 3:42 pm

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 4 guests