[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Possible ruby bug involving threads and IO

Lucas Nussbaum

1/4/2005 11:12:00 PM

Hi,

I ran into a problem demonstrated by the following code :

#!/usr/bin/ruby

require 'thread'

Thread::new {
while true do
puts "before read MOTD"
str = IO.read("/etc/motd")
puts "after read MOTD"

puts "before read UPTIME"
str = IO.read("/proc/uptime")
puts "after read UPTIME"
end
}

while true do
end

Ruby hangs on IO.read("/proc/uptime").

Note that it works with linux 2.4 (tested : 2.4.27) but not linux 2.6
(tested : 2.6.9)
It only fails with files on the proc filesystem.

Any ideas ?

Thanks,
--
| Lucas Nussbaum
| lucas@lucas-nussbaum.net lnu@gnu.org GPG: 1024D/023B3F4F |
| jabber: lucas@linux.ensimag.fr http://www.lucas-nu... |
| fingerprint: 075D 010B 80C3 AC68 BD4F B328 DA19 6237 023B 3F4F |



2 Answers

William Morgan

1/4/2005 11:30:00 PM

0

Excerpts from Lucas Nussbaum's mail of 4 Jan 2005 (EST):
> Ruby hangs on IO.read("/proc/uptime").

This is probably the same issue described in:
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

The upshot is that certain files in /proc/ seem to hang on a select()
call, which Ruby uses for I/O within threads. You can do an strace and
watch the difference between doing this from within and from without a
Thread.

My workaround was something along the lines of:
system "cat /proc/#{file} > #{tmpfile}"
f = File.open tmpfile

I don't know that there's a better solution.

--
William <wmorgan-ruby-talk@masanjin.net>


Lucas Nussbaum

1/4/2005 11:38:00 PM

0

On Wed, Jan 05, 2005 at 08:30:09AM +0900, William Morgan <wmorgan-ruby-talk@masanjin.net> wrote:
> Excerpts from Lucas Nussbaum's mail of 4 Jan 2005 (EST):
> > Ruby hangs on IO.read("/proc/uptime").
>
> This is probably the same issue described in:
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-t...

true

> The upshot is that certain files in /proc/ seem to hang on a select()
> call, which Ruby uses for I/O within threads. You can do an strace and
> watch the difference between doing this from within and from without a
> Thread.
>
> My workaround was something along the lines of:
> system "cat /proc/#{file} > #{tmpfile}"
> f = File.open tmpfile
>
> I don't know that there's a better solution.

IO.popen("/bin/cat /proc/uptime")

But still, that's not very satisfying ...
--
| Lucas Nussbaum
| lucas@lucas-nussbaum.net lnu@gnu.org GPG: 1024D/023B3F4F |
| jabber: lucas@linux.ensimag.fr http://www.lucas-nu... |
| fingerprint: 075D 010B 80C3 AC68 BD4F B328 DA19 6237 023B 3F4F |