File.read block in Thread

Ruby Version: ruby 1.8.7 (2010-04-20 patchlevel 254) [i686-linux]
Ruby-Gnome 2 Version: ruby-gtk2-0.19.4.tar.gz

Code:
require ‘rubygems’
require ‘gtk2’

w=Gtk::Window.new
w.signal_connect(‘destroy’) do
Gtk.main_quit
end
w.show_all

Thread.new do
while true
puts File.read FILE # blocked, if comment the line, the script
will print ‘—’ every second as expect.
puts ‘-’*80
sleep 1
end
end
Gtk.main

How to solve that?
Thanks

On 10 May 2010 18:43, Miao J. [email protected]
wrote:

Ruby Version: ruby 1.8.7 (2010-04-20 patchlevel 254) [i686-linux]
Ruby-Gnome 2 Version: ruby-gtk2-0.19.4.tar.gz

[…]

How to solve that?

It works as expected for me. That is, it prints out the file followed
by the line of dashes every second. I’m using the packages in
Ubuntu 10.4 (lucid): Ruby 1.8.7 and ruby-gnome 19.3.

I got fooled at the beginning though because the file is as big as
my terminal. So it prints out a new page and I don’t see anything
unless I scroll back.

     MikeC

Mike C. wrote:

On 10 May 2010 18:43, Miao J. [email protected]
wrote:

Ruby Version: ruby 1.8.7 (2010-04-20 patchlevel 254) [i686-linux]
Ruby-Gnome 2 Version: ruby-gtk2-0.19.4.tar.gz

[…]

How to solve that?

It works as expected for me. That is, it prints out the file followed
by the line of dashes every second. I’m using the packages in
Ubuntu 10.4 (lucid): Ruby 1.8.7 and ruby-gnome 19.3.

I got fooled at the beginning though because the file is as big as
my terminal. So it prints out a new page and I don’t see anything
unless I scroll back.

     MikeC

Thank you for reply.
Quite strange, I still have no idea how to solve the Gtk.main or linux
conflict(maybe), but it solved when I try Gtk.events_pending? and
Gtk.main_iteration.

Patched code:
require ‘rubygems’
require ‘gtk2’

w=Gtk::Window.new
w.signal_connect(‘destroy’) do
$done=true
end
w.show_all

Thread.new do
while true
puts File.read FILE
puts ‘-’*80
sleep 1
end
end

$done=false
begin
while Gtk.events_pending?
Gtk.main_iteration
end
sleep 0.02
end until $done