How to stop execution in python's Idle?

  • Thread starter deltapapazulu
  • Start date
In summary, the conversation revolves around the user's attempt to calculate the extremely large number 99999**999999999 using the Python Idle application. The user's computer becomes unresponsive and the user seeks advice on how to stop the calculation or break out of the application without closing it. An expert responds by explaining that the number is too large to compute and suggests using Ctrl-C or killing the application more forcefully. The user also shares their observations on the computer's performance and the application's behavior while attempting the calculation.
  • #1
deltapapazulu
84
12
I scoured internet for answer to no avail. I am new to python and was toying with large calculations, 99999**999999999 for instance, and Idle started running and became completely non responsive. Ctrl-c didn't work. The menu in shell became non-responsive. I had to x-out & restart Idle. There's got to be a way to stop a process from executing in Idle. If there is not, that's ashamed.

I repeated the 99999**999999999 numerous times to see if I couldn't figure it out, but couldn't. Each time the window hazed over and the run wheel thing kept spinning and couldn't be stopped.

This is merely a curiosity.
 
Technology news on Phys.org
  • #2
The number you're trying to calculate is way too large to compute in most programming languages. I'm not an expert in Python, but I believe that a typical Python implementation stores real numbers in 64 bits, which means that the largest such number would be 263, which is roughly 1021. The number you're trying to calculate is roughly 105,000,000,000.

In a nutshell, if your computer hangs when you try to calculate 99999999999999, then don't do that.
 
  • #3
Mark44 said:
The number you're trying to calculate is way too large to compute in most programming languages. I'm not an expert in Python, but I believe that a typical Python implementation stores real numbers in 64 bits, which means that the largest such number would be 263, which is roughly 1021. The number you're trying to calculate is roughly 105,000,000,000.

In a nutshell, if your computer hangs when you try to calculate 99999999999999, then don't do that.

Perhaps I should have been more clear. I am completely aware that the calculation was outside the range of computationability. That is precisely why I attempted it. I wanted to see how python Idle would respond to it, i.e. whether it would give me a particular error message. Then when it responded the way it did I became curious as to how to break out of its locked up state without closing the application. To me that is a very reasonable thing to desire to know when learning a new application.

I actually think it is kind of amusing that you thought that the intention of my thread was to find out what 99999^9999999999 was. It should have been clear in my thread title that that was not what I was inquiring into. But thanks anyway.
 
  • #4
Ctrl-C should work: try with the infinite loop while True: pass.

The problem here is presumably that the program is spending its time in a long-running native routine. Python catches the signal and delays the KeyboardInterrupt until after the native routine has finished executing, which means you'll just have to wait. (or kill it more forcefully)

Incidentally, 99999**999999999 is an integer calculation. Assuming you have 4 gigabytes or so of memory available, then given enough time, python will compute it exactly. (barring implementation errors) Of course, python doesn't use efficient arithmetic, so "enough time" is probably on the order of centuries. (And I suspect I'm underestimating)
 
  • #5
Hurkyl said:
Ctrl-C should work: try with the infinite loop while True: pass.

The problem here is presumably that the program is spending its time in a long-running native routine. Python catches the signal and delays the KeyboardInterrupt until after the native routine has finished executing, which means you'll just have to wait. (or kill it more forcefully)

Incidentally, 99999**999999999 is an integer calculation. Assuming you have 4 gigabytes or so of memory available, then given enough time, python will compute it exactly. (barring implementation errors) Of course, python doesn't use efficient arithmetic, so "enough time" is probably on the order of centuries. (And I suspect I'm underestimating)

ctrl-c worked for the loop.

I ran the power calculation again to check performance in task manager. CPU usage of my Intel E8400 hovers around 55% with ram usage around 1.27gb(out of 4). I was definitely trying to compute it. Right now I am just letting it continue.

Also, before that I crept the power from 99999**9 to 99999**99999. At 99999**9999 it generated about 10 pages worth of the number. The fifth 9 in the power, though, put it in that "leave me alone I'm calculating mode" again.

Ok so right now it has been calculating 99999**999999999 for about 7 minutes and I have noticed the ram usage has been creeping up. Now it is at 1.34gb. CPU still at 55%.

Now ram is at 1.36gb. 10 minutes.

Anyway thanks for response. ctrl-c still being sidelined. Oh well, just a curiousity.
 

Related to How to stop execution in python's Idle?

1. How do I stop execution in python's Idle if my code gets stuck in an infinite loop?

To stop execution in python's Idle when your code is stuck in an infinite loop, you can press the "Ctrl + C" keys on your keyboard. This will send a KeyboardInterrupt signal to the program and stop the execution.

2. Is there a way to pause execution in python's Idle and resume it later?

Yes, you can use the "Ctrl + Z" keys on your keyboard to pause execution in python's Idle. This will suspend the program and return you to the command prompt. You can then use the "fg" command to resume execution.

3. Can I stop execution in python's Idle without closing the program?

Yes, you can use the "Ctrl + Alt + Del" keys on your keyboard to bring up the Task Manager and end the python process. This will stop the execution without closing the program.

4. How do I stop execution in python's Idle if I encounter an error?

If you encounter an error during execution in python's Idle, you can use the "Ctrl + C" keys on your keyboard to stop the execution. This will print the error message and stop the program.

5. Is there a way to stop execution in python's Idle without using keyboard shortcuts?

Yes, you can use the "sys.exit()" function in your code to stop execution in python's Idle. This will terminate the program and return you to the command prompt.

Similar threads

Back
Top