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,
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
so far, this seems to work fine on my box? what’s you platform/arch/ruby
version, etc?
-a
···
On Wed, 28 Apr 2004, Ken Hilton wrote:
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,
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
–
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
===============================================================================
so far, this seems to work fine on my box? what’s you platform/arch/ruby
version, etc?
-a
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.
···
On Wed, 28 Apr 2004, Ken Hilton wrote:
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,
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
EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
URL :: Solar-Terrestrial Physics Data | NCEI
TRY :: for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done
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.
If anyone knows the work-around to this, please add.
Hope this is of general use for STDIN#gets in a thread.
It checks for input in the keyboard buffer and if there
is any, does a normal (blocking) STDIN#gets.
Thanks much. I’ll give it a try. Something I also noticed was the
following: select([$stdin],nil,nil) always returns true when called
immediately before calling gets() on Windows. Hmmm…
If anyone knows the work-around to this, please add.
Hope this is of general use for STDIN#gets in a thread.
It checks for input in the keyboard buffer and if there
is any, does a normal (blocking) STDIN#gets.