如何在shell上停止没有错误消息的Python脚本?

2024-05-19 03:37:51 发布

您现在位置:Python中文网/ 问答频道 /正文


Tags: python
1条回答
网友
1楼 · 发布于 2024-05-19 03:37:51

当您将CTRL+C发送到Python脚本时,它会引发KeyboardInterrupt异常,因此您可以执行如下操作

try:
    ... Work goes here ...
except KeyboardInterrupt:
    sys.exit(0)

相关问题 更多 >

    热门问题