The easiest way is to just interrupt it with the usual Ctrl-C
(SIGINT).
try:
while True:
do_something()
except KeyboardInterrupt:
pass
Since Ctrl-C
causes KeyboardInterrupt
to be raised, just catch it outside the loop and ignore it.
More Related Contents:
- How to break out of while loop in Python?
- Can someone explain what all the codes mean? PYTHON [closed]
- in a while loop, where should you place a variable for counting?
- Why is this python while loop not ending?
- How to end a python program without it going to the next line of code [duplicate]
- Python Code that returns true while key is pressed down false if release?
- How to break out of multiple loops?
- How to emulate a do-while loop?
- Else clause on Python while statement
- How to check if all elements of a list match a condition?
- How can I break out of multiple loops?
- How do I plot in real-time in a while loop using matplotlib?
- Python: How to keep repeating a program until a specific input is obtained? [duplicate]
- What does a semicolon do?
- break and continue in function
- Converting for loops to while loops in python
- Using a loop to create and assign multiple variables (Python) [duplicate]
- Python – Infinite while loop, break on user input
- Mixing files and loops
- How can I make sense of the `else` clause of Python loops?
- for or while loop to do something n times [duplicate]
- tkinter root.mainloop with While True loop
- Python loop to run for certain amount of seconds
- Assignment Condition in Python While Loop
- How do I plot in real-time in a while loop?
- Visibility of global variables in imported modules
- Take a screenshot via a Python script on Linux
- Python: best practice and securest way to connect to MySQL and execute queries
- Is there a way to get the largest integer one can use in Python? [duplicate]
- How can you find unused functions in Python code?