tags:

views:

97

answers:

1

I am writing an application, which shall work with networks. As a GUI I am using rubyqt. To determine if a Server is up I have to ping it (with net/ping). But I ran in to a problem. If the server is down, the GUI freezes for the timeout, even if I put the code in a Thread or IO.popen loop eg.

Thread.new('switch') do
  if Net::PingExternal.new("195.168.255.244",timeout=0.9).ping then
      down = false
    else
      down = true
  end
end

will freeze for 0.9 seconds. As the QtThreads are not yet working with rubyqt, does somebody have an idea to make the GUI don't freeze (apart from reducing the timeout)?

I was thinking about putting the pinging-part in an external program, which writes the status (up/down) in a file, which the actual program then reads, but this solution seems to be a bit clumsy.

A: 

Have you considered abstracting that operation from the request altogether? If you move the costly operation to an external library you could easily queue it up and execute it using something like delayed_job (http://github.com/tobi/delayed_job/tree/master) which would remove the risk of it halting the request at all.

Maybe this is what you are looking for...?

joshnesbitt
The delayed_job library isn't what I need, it would only queue the requests up. But this behaviour is unacceptable (and I think there wouldn't ever be a free timeslot inwhich dj could send the pings), because the pings have to be sent every second. I exported the pinging to an external program (data exchange over files), which works fine, but I would prefer all the functions in 1 program.
Deadolus