Hey list,
I have a problem with trapping signals in the main thread whilst a
subprocess is running in another thread. The signal is properly trapped,
however it doesn’t seem to stop the signal from being sent to the
subprocess. Is this an inherent side effect of green thread
implementations?
Can anyone suggest a workaround?
The code here demonstrates my problem. Run it, and hit ^C. My
expectation
was not to see ‘killed :(’ until the 10 seconds are up.
#!/usr/bin/ruby
class Sleeper < Thread
def initialize
super do
IO.popen(‘sleep 10’) {|f| puts f.gets }
puts “killed :(”
end
end
end
Signal.trap(‘INT’) { puts “Signal trapped.” }
a = Sleeper.new
a.join
Cheers
Ian