On Wed, Jun 16, 2010 at 7:29 AM, Kyle Zhou <[email protected]> wrote:

> Basically, I want to catch Ctrl+C after top_block.run()
> For example
>
>     try:
>
>         my_top_block().run()
>
>     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
_______________________________________________
Discuss-gnuradio mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to