[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] KeyboardInterrupt not being caught in top_block

From: Michael Berman
Subject: Re: [Discuss-gnuradio] KeyboardInterrupt not being caught in top_block
Date: Wed, 16 Jun 2010 10:57:09 -0700

On Wed, Jun 16, 2010 at 7:29 AM, Kyle Zhou <address@hidden> wrote:
Basically, I want to catch Ctrl+C after top_block.run()
For example



    except KeyboardInterrupt:

        print "Ctrl+C has been pressed. Exiting."

However, when Ctrl+C is pressed, the program exits straight away without executing the print function.

It seems that KeyboardInterrupt is not propagated to the main thread?

What am I doing wrong?

The "except KeyboardInterrupt" catches anything typed on the keyboard as a normal character.  This interrupt is thrown so that the OS can capture the input from the keyboard no matter what else is going on, and that the data being sent to the computer is not lost.

The Ctrl+C creates a special command generated by the OS called SIGINT.  The default way a process handles this signal is to kill itself.  In order to have your own process handle this kind of interrupt, you need to need to create a specific method to capture SIGINT and handle it in your own way.

Attached is a snippet of code from Stack Overflow (http://stackoverflow.com/questions/1112343/how-do-i-capture-sigint-in-python) that shows how to do what you need.


-Michael Berman

reply via email to

[Prev in Thread] Current Thread [Next in Thread]