Is there a way to keep tracebacks from coming up when you hit Ctrl+c,
i.e. raise KeyboardInterrupt
in a Python script?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
Catch it with a try/except block:
Try this:
This way you don't need to wrap everything in an exception handler.
Is the simplest way, assuming you still want to exit when you get a Ctrl+c.
If you want to trap it without a try/except, you can use a recipe like this using the
signal
module, except it doesn't seem to work for me on Windows..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).
Catch the
KeyboardInterrupt
: