我有以下代码:
import click
@click.command()
def main():
while True:
pass
try:
main()
except KeyboardInterrupt:
print('My own message!')
当我按 Ctrl+C 退出程序时,我想打印我自己的消息。然而,点击截获错误,这是输出:
^C
Aborted!
如何阻止点击处理错误?
最佳答案
我想我已经用这段代码解决了我的问题!希望这是处理我的问题的正确方法。
import click
@click.command()
def main():
while True:
pass
try:
main(standalone_mode=False)
except click.exceptions.Abort:
print('My own message!')
关于python - 停止点击(python 模块)捕捉/处理 KeyboardInterrupt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61163266/