473,387 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

keyboard command to break out of infinite loop?

Running Python on Win XP.

When running commands with the interpreter, if you get stuck in a while
loop, is there a keyboard command to break out of it?

Or is the only way out a triple-finger salute and End Task?

rd

Apr 16 '06 #1
5 27145
Try CTRL + C. If it doesn't work, CTRL + Pause/Break should also work
(if you're running it from the CLI).

HTH

Apr 16 '06 #2

BartlebyScrivener wrote:
Running Python on Win XP.

When running commands with the interpreter, if you get stuck in a while
loop, is there a keyboard command to break out of it?

Or is the only way out a triple-finger salute and End Task?

rd


ctrl+c

or ctrl+c+enter

Apr 16 '06 #3
Thank you, both. I'll put in on a sticky!

rick

Apr 16 '06 #4
zweistein wrote:
Try CTRL + C. If it doesn't work, CTRL + Pause/Break should also work
(if you're running it from the CLI).

HTH

Note: this will raise a KeyboardInterrupt exception, which you might
inadvertently be catching. If you have been lazy and written:
try:
<watched code>
except:
<some code>
You may get to <some code> if the Control-C (or Control-Break) is
processed in the <watched code> section. This is one reason we always
urge people to be specific about the exceptions they expect. The
following code demonstrates what is happening:

try:
response = raw_input('Prompt: ')
except:
print 'Got here'

If you run this code and hit Control-C in response to the prompt
(guaranteeing you are inside the try-except block), you will see
a "Got here" printed. Similarly, you can look for this one exception,
and treat it specially:

try:
response = raw_input('Prompt: ')
except KeyboardInterrupt, error:
print 'Got here with "%s" (%r)' % (error, error)

Running this and entering Control-C at the prompt will show you
that the exception you get from a KeyboardInterrupt has a reasonable
repr (the result of the %r translation), but its str conversion (the
result of the %s translation) is a zero length string (which is kind
of hard to see in a print).

So, avoid "except:" when catching exceptions, and your life will be
happier.

--Scott David Daniels
sc***********@acm.org
Apr 16 '06 #5
Thank you, Scott. I'm still learning my exceptions (obviously, or I
wouldn't get stuck in a while loop ;).

That was instructive. On my machine, it is Ctrl + Break that does it.
Ctrl + C doesn't do anything.

What I should really do is figure out roughly how many times the while
loop should run, and then put an outer limit on it, so that it will run
normally as long as it doesn't exceed x, after which it breaks and
says, "Hey, Dummy, you were headed into an infinite loop."

Could be a good exercise.

Thank you again.

rick

Apr 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

43
by: Gremlin | last post by:
If you are not familiar with the halting problem, I will not go into it in detail but it states that it is impossible to write a program that can tell if a loop is infinite or not. This is a...
1
by: Rene | last post by:
I got stuck on an infinite loop on the "Paint" event of my custom control and I was not able to "ctrl-break" my way out of it. After trying everything, I had to ctrs-alt-delete to shut down the...
13
by: Sunbags | last post by:
Hello, I'm a 2nd year Computer Engineering student and I have a problem with my VB6 code. I've just started learning VB6 for a project in which we have to create a form which displays the...
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
2
by: Lawrence Krubner | last post by:
Imagine a template system that works by getting a file, as a string, and then putting it through eval(), something like this: $formAsString = $controller->command("readFileAndReturnString",...
8
by: Pivot_Tables | last post by:
Hi, I have created a recursive SQL Query in DB2 and it works fine until some point in the tree where the data gets into infinite loop. Below are some sample data from my relationship table. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.