What is the difference between Ctrl-C and SIGINT?

前端 未结 2 543
半阙折子戏
半阙折子戏 2020-12-13 09:35

I have been debugging a Python program which segfaults after receiving a KeyboardInterrupt exception. This is normally done by pressing Ctrl+C from t

2条回答
  •  别那么骄傲
    2020-12-13 09:57

    As described here :

    Python installs a small number of signal handlers by default: SIGPIPE is ignored (so write errors on pipes and sockets can be reported as ordinary Python exceptions) and SIGINT is translated into a KeyboardInterrupt exception. All of these can be overridden.

    so, the behaviour should be the same between sending a SIGINT and a Ctrl + c.

    But, you have to be carefull with the KeyboardInterrupt, if somewhere in your code you've got a

    try:
       ...
    except:   # notice the lack of exception class
       pass
    

    this will "eat" the KeyboardInterrupt exception.

提交回复
热议问题