Python 隐藏 ^C 从 SIGINT

chr*_*ris 5 python-2.7

我正在使用信号处理程序捕获 ctrl-c 并想知道是否有比 go os.system("\b") 或类似方法更好的方法来隐藏打印到终端的 ^C 。我只真正关心 Unix。

    def read(self, time_s):

        setup = ['Sensor', 'sensors', '\x00']

        # Closure for signal handler to allow access to self
        def sigintHandler(*args):
            self.close()
            sys.stdout.write('\b\b\r')  # Current solution
            sys.stdout.flush()
            sys.exit(0)

        signal.signal(signal.SIGINT,sigintHandler)
Run Code Online (Sandbox Code Playgroud)

编辑

我目前的解决方案是上面

小智 2

使用将清除输出中的print('\b\b\r')烦人内容。^C