Answer by wim for Remove traceback in Python on Ctrl-C
According to Proper handling of SIGINT/SIGQUIT, the only way to exit correctly if you're catching a SIGINT is to subsequently kill yourself with a SIGINT signal (see the section titled "How to be a...
View ArticleAnswer by Roman Kazakov for Remove traceback in Python on Ctrl-C
suppress exception using context manager:from contextlib import suppressdef output_forever(): while True: print('endless script output. Press ctrl + C to exit')if __name__ == '__main__': with...
View ArticleAnswer by Ryan Bell for Remove traceback in Python on Ctrl-C
import systry: print("HELLO") english = input("Enter your main launguage: ") print("GOODBYE")except KeyboardInterrupt: print("GET LOST")
View ArticleAnswer by jleahy for Remove traceback in Python on Ctrl-C
Try this:import signalimport syssignal.signal(signal.SIGINT, lambda x, y: sys.exit(0))This way you don't need to wrap everything in an exception handler.
View ArticleAnswer by toksaitov for Remove traceback in Python on Ctrl-C
Also note that by default the interpreter exits with the status code 128 + the value of SIGINT on your platform (which is 2 on most systems). import sys, signal try: # code... except KeyboardInterrupt:...
View ArticleAnswer by agf for Remove traceback in Python on Ctrl-C
import systry: # your codeexcept KeyboardInterrupt: sys.exit(0) # or 1, or whateverIs the simplest way, assuming you still want to exit when you get a Ctrl+c.If you want to trap it without a...
View ArticleAnswer by ʇsәɹoɈ for Remove traceback in Python on Ctrl-C
try: your_stuff()except KeyboardInterrupt: print("no traceback")
View ArticleAnswer by Manny D for Remove traceback in Python on Ctrl-C
Catch it with a try/except block:while True: try: print "This will go on forever" except KeyboardInterrupt: pass
View ArticleAnswer by icktoofay for Remove traceback in Python on Ctrl-C
Catch the KeyboardInterrupt:try: # do somethingexcept KeyboardInterrupt: pass
View ArticleRemove traceback in Python on Ctrl-C
Is there a way to keep tracebacks from coming up when you hit Ctrl+c, i.e. raise KeyboardInterrupt in a Python script?
View Article
More Pages to Explore .....