How do I capture SIGINT in Python?

前端 未结 12 1497
长发绾君心
长发绾君心 2020-11-21 22:54

I\'m working on a python script that starts several processes and database connections. Every now and then I want to kill the script with a Ctrl+C sign

12条回答
  •  感动是毒
    2020-11-21 23:10

    You can handle CTRL+C by catching the KeyboardInterrupt exception. You can implement any clean-up code in the exception handler.

提交回复
热议问题