Stopping the Distributed Ruby Service

I have a script that starts the DRb service before deploying the handler object and waiting through DRb.thread.join . I would like the script to be executed until it was 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 seems to be deadlock in 1.9 (on OS X 10.6.7). Sampling a process shows a pair of threads spinning in semaphore_wait_signal_trap .

I assume that I am doing something different than what I call stop_service , but I'm not sure what. Can someone tell me how to do this right?

+6
ruby distributed drb
source share
2 answers

Ok, I think I found a solution. If you replace the source code with

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

Ctrl-C runs and stops the service.

+6
source share

DRb.thread.join causes the calling thread to wait for the completion of the DRb execution thread. If you want to catch the INT signal, I would rather go with the following code.

 $execute = true DRb.start_service Signal.trap("INT") { $execute = false } while $execute sleep 1 end DRb.stop_service 

Please note that in this case there is no DRb.thread.join . Also, a preferred method is to capture a signal rather than save the interrupt exception.

0
source share

All Articles