Is there anyway I can make my script execute one of my functions when Ctrl+c
is hit when the script is running?
相关问题
- 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
Sure.
Take a look at signal handlers. CTRL-C corresponds to SIGINT (signal #2 on posix systems).
Example:
Use the KeyboardInterrupt exception and call your function in the
except
block.