From: Ken Hilton Date: 2004-04-28T10:29:03+09:00 Subject: DRb & thread blocking. Greetings, I added a post earlier today in hopes someone might know right off hand why the Ruby progam I've written was not functioning as expected. I didn't have a lot to go on, nor to share so someone could advise me. So, I spent some time stripping my problem child down to its bare minimum and the problem is persisting. Can anyone explain to my why this little program seems to block DRb from responding to calls when a thread in the same app has called gets()? Here's the code & instructions. Thanks in advance for any insight you can provide. I hope to return the favor in the future. -------------------------- # app.rb # Instructions: run this program (app.rb) in one shell THEN run # myclnt.rb in a separate shell. If the call to "gets" at line # 43 (below) is active, calls to MyServer::service from myclnt.rb # seem to be blocked. Pressing [enter] (w/a short sleep provided # to better illustrate the problem), allows the DRb calls from # myclnt.rb to be processed, that is right up until the next call # to gets. Commenting out the call to gets, re-running app.rb, # and then re-running myclnt.rb shows the problem has "gone away." # require 'thread' require 'drb' # MyServer handles calls from myclnt.rb - just returns an I'm alive message. class MyServer def service "MyServer is alive!!!" end end class App def initialize() # array of threads, 1 for DRb and 1 for my command loop, @services = [] end def run() # Start MyServer service and store thread. svr = MyServer.new(); DRb.start_service('druby://localhost:9000', svr); @services << DRb.thread; # Start command loop. *** When "gets" is called DRb appears to block:. # calls to it from myclnt.rb stall until enter is pressed, thereby # giving enough cycles to DRb.thread to respond to the request?!?!? @services << Thread.new { while true print "Prompt> " # comment out the next line and then rerun app.rb and myclnt.rb #exit if gets.chomp() == "exit"; sleep(1) end } @services.each {|svc| svc.join()} end end App.new().run(); -------------------------- # myclnt.rb require 'drb' puts "Running my client..." DRb.start_service(nil,nil) while true svr = DRbObject.new(nil, 'druby://localhost:9000') puts "Calling server..." puts "Server returned: " + svr.service; end