[英]How can I override the keyboard interrupt? (Python)
无论如何,当脚本运行时,当我Ctrl+c
时,我可以让我的脚本执行我的一个功能吗?
当然。
try:
# Your normal block of code
except KeyboardInterrupt:
# Your code which is executed when CTRL+C is pressed.
finally:
# Your code which is always executed.
使用KeyboardInterrupt异常并在except
块中调用您的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.