Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stopping a Distributed Ruby Service

I have a script that starts up a DRb service, before spawning a handler object and waiting via DRb.thread.join. I would like the script to run until explicitly killed, so I added

trap "INT" do
  DRb.stop_service
end

which successfully stops the DRb service and exits under Ruby 1.8, but under 1.9 seems to deadlock (on OS X 10.6.7). Sampling the process shows a couple of threads spinning in semaphore_wait_signal_trap.

I assume that I'm doing something wrong in the way I'm calling stop_service, but I'm not sure what. Could anyone give me any pointers around how to correctly go about it?

like image 747
kfb Avatar asked Mar 28 '11 14:03

kfb


1 Answers

Okay, I think I have found the solution. If I replace the original code with

begin
  DRb.thread.join
rescue Interrupt
ensure
  DRb.stop_service
end

The Ctrl-C works and stops the service.

like image 93
kfb Avatar answered Oct 31 '22 19:10

kfb