Feature #12693
closed
Updated by sonots (Naotoshi Seo) almost 9 years ago
- Subject changed from Want to a way to receive EINTR on Process.waitpid to Want a way to receive EINTR on Process.waitpid
Updated by shyouhei (Shyouhei Urabe) almost 9 years ago
Naotoshi Seo wrote:
However, ruby implementation of Process.waitpid does not raise EINTR
No you don't. It is an extremely bad idea to use signal to interrupt execution.
Is it you must use signal for some reason or you just want to avoid infinite blocking? What if, for instance waitpid would take extra argument as timeout?
Updated by sonots (Naotoshi Seo) almost 9 years ago
I am currently using Timeout hack for when I wanted to get EINTR like https://.com/sonots/ruby-server-starter/blob/7fbc8db2548c215aae02afef385caa683040bd8a/lib/server/starter.rb#L215-L223.
I was glad if I did not need to write such a hacky code.
Updated by sonots (Naotoshi Seo) almost 9 years ago
If adding an option to raise EINTR is not acceptable, adding timeout option is acceptable for my case.
Updated by naruse (Yui NARUSE) almost 9 years ago
You can raise exception on main threadh by Thread.main.raise in trap.
Updated by sonots (Naotoshi Seo) almost 9 years ago
It worked like a charm :)
test.rb
puts Process.pid
trap(:CONT) do
raise 'CONT'
end
_pid = fork do
sleep 10
end
begin
Process.waitpid(-1)
rescue => e
puts e.backtrace.join("\n")
end
Sending signal, I got
test.rb:4:in `block in <main>'
test.rb:12:in `waitpid'
test.rb:12:in `<main>'
Updated by sonots (Naotoshi Seo) almost 9 years ago
- Status changed from Open to Rejected