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.
Thanks Eric,
I am using GNU Radio git depository installed a month ago.
tried on Cygwin 1.7.5+WinXP and OSX 10.6.3+Macbook, both behaved the
same.
I’ll try ubuntu tomorrow when I have access to another PC.
Ctrl+C exits the program but not caught by except.
On Thu, Jun 17, 2010 at 02:53:28PM +1000, Kyle Z. wrote:
Thanks Eric,
I am using GNU Radio git depository installed a month ago.
tried on Cygwin 1.7.5+WinXP and OSX 10.6.3+Macbook, both behaved the same.
I’ll try ubuntu tomorrow when I have access to another PC.
Ctrl+C exits the program but not caught by except.
Kyle,
Are you trying to set a handler for a signal somewhere in your code?
If so, it’s unlikely to work. In general signals and threads don’t
play together well. A bit of googling will show you the mine field.
If you’re trying to catch a std::exception, that should work fine.
Are you trying to set a handler for a signal somewhere in your code?
If so, it’s unlikely to work. In general signals and threads don’t
play together well. A bit of googling will show you the mine field.
If you’re trying to catch a std::exception, that should work fine.
Eric
Hi Eric
I did not set any handler except ‘except KeyboardInterrupt: …’
I tried it on Ubuntu as well which turned out to fail.
Yes, I agree with you that it’s likely the problem of coworking of
signals and threads.
I tried a single threaded program where the same mechanism did work.
So I will change my approach completely.
Thanks for making things clarified.
Kyle
On Fri, Jun 18, 2010 at 06:14:55PM +1000, Kyle Z. wrote:
Eric
Hi Eric
I did not set any handler except ‘except KeyboardInterrupt: …’
I tried it on Ubuntu as well which turned out to fail.
Yes, I agree with you that it’s likely the problem of coworking of signals and threads.
I tried a single threaded program where the same mechanism did work.
So I will change my approach completely.
Thanks for making things clarified.
Kyle
Kyle,
I just spent a few minutes reviewing the guts of the code. We do all
the magic to detect ^C in python, and then just tell the flow graph to
stop cleanly and wait for it to finish. We do not propagate the
python exception since it’s often times caught “in the wrong thread”.
Summary: the built in behavior is to map ^C (SIGINT) into code that
stops the graph. That code is very tricky, took a long time to get
working reliably, and I suggest you don’t mess with it. However, if
you’re curious, see gnuradio-core/src/python/gnuradio/gr/top_block.py
and gnuradio-core/src/lib/runtime/gr_top_block.i
Eric
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.