chris
chris

Reputation: 4996

Python hide ^C from sigint

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

Upvotes: 7

Views: 1212

Answers (1)

dbrennan
dbrennan

Reputation: 21

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

Upvotes: 2

Related Questions