wxruby unfriendly to Ruby threads?

G

Guillaume Marcais

I have a GUI application with a bunch of threads proxying network
information around. But the network communication seems very slow if not
stopped. To make sure, I added a "keep alive" thread:

Thread.new do
loop do
puts("Keep alive #{Time.now}")
sleep 1
end
end

This thread hangs after a little while and stop outputting anything. If
I move the mouse over the window, a bunch of lines are printed by the
keep alive thread, all at once with the same time, and then it hangs
until the next GUI event.

Is this a known problem? Or am I completely misguided?

Guillaume.
 
W

Wink Saville

Guillaume said:
I have a GUI application with a bunch of threads proxying network
information around. But the network communication seems very slow if not
stopped. To make sure, I added a "keep alive" thread:

Thread.new do
loop do
puts("Keep alive #{Time.now}")
sleep 1
end
end

This thread hangs after a little while and stop outputting anything. If
I move the mouse over the window, a bunch of lines are printed by the
keep alive thread, all at once with the same time, and then it hangs
until the next GUI event.

Is this a known problem? Or am I completely misguided?

Guillaume.
On my system running windows I need to redefine puts as below to flush
the output:

def puts(s)
STDOUT.puts(s)
STDOUT.flush
end

As for the threads, how many is a bunch? I've been looking at the
scheduler and it looks to me that each time a thread is scheduled the
entire list of threads is looped through at least twice and as many as 5
times. I'm looking into other possible algorithms, but I'm a newbie so
not sure what progress I'll make. But it looks to be an interesting
problem and I believe it is solvable.

Cheers,

Wink
 
G

Guillaume Marcais

On my system running windows I need to redefine puts as below to flush
the output:

def puts(s)
STDOUT.puts(s)
STDOUT.flush
end

As for the threads, how many is a bunch?

I am using net-ssh, which uses threads internally, so my count is only
approximated. I guess between 10 and 15 threads, mostly waiting on
sockets. The total amount of traffic going through is not huge, but it
has to keep flowing or the applications consider the connection to be
lost fairly quickly.
I've been looking at the
scheduler and it looks to me that each time a thread is scheduled the
entire list of threads is looped through at least twice and as many as 5
times. I'm looking into other possible algorithms, but I'm a newbie so
not sure what progress I'll make. But it looks to be an interesting
problem and I believe it is solvable.

Well, it seems that, some reasons, the threads are not scheduled if no
GUI activity is there. If I keep moving my mouse over my application
window, the forwarding works, if I stop, it hangs and disconnect.

By the way, the platform is Linux, but eventually the code will be
ported to Windows too.

In the end, I think I'll spawn off a separated process (and communicate
with Drb most likely) to do the net-ssh trickery. After reading on how
threading works with wxRuby, I feel uneasy keeping everything in the
same process and having the IO so much under the control of the GUI
library.

Guillaume.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

wxruby and threads 8
Threads 1
Ruby & Threads 3
background threads 5
New to ruby, using threads 6
C extension and Ruby threads 3
Threads + Forks in Ruby 1.9.1p129 5
Using threads to show progress 21

Members online

No members online now.

Forum statistics

Threads
474,181
Messages
2,570,970
Members
47,537
Latest member
BellCorone

Latest Threads

Top