Quantcast
Channel: Remove traceback in Python on Ctrl-C - Stack Overflow
Browsing all 10 articles
Browse latest View live

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 Article



Answer 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 Article

Answer 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 Article

Answer 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 Article

Answer 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 Article


Answer 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 Article

Answer by ʇsәɹoɈ for Remove traceback in Python on Ctrl-C

try: your_stuff()except KeyboardInterrupt: print("no traceback")

View Article

Answer 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 Article


Answer by icktoofay for Remove traceback in Python on Ctrl-C

Catch the KeyboardInterrupt:try: # do somethingexcept KeyboardInterrupt: pass

View Article


Remove 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
Browsing all 10 articles
Browse latest View live




Latest Images