Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python hide ^C from sigint

Tags:

python-2.7

I'm catching ctrl-c with a signal handler and was wondering if there is a nicer way to hide the ^C that is printed to terminal than go os.system("\b") or similar. I only really care about 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)

Edit

My current solution is above

like image 221
chris Avatar asked Nov 09 '22 22:11

chris


1 Answers

Using print('\b\b\r') will clear the annoying ^C from the output.

like image 70
dbrennan Avatar answered Dec 02 '22 21:12

dbrennan