On Mar 8, 5:27 pm, Christopher Tasma <tasm... / gmail.com> wrote:
> Hello all,
>
> I was writing a simple 'file sharing' program with QT and ruby.  I
> noticed when running two clients on one machine for testing some odd
> behavior with the focus.  When a peer receives a request from and serves
> files to another peer, it does so from a file server running in a
> separate thread.
>
> I noticed that the programs seem to die when there is no focus on the
> main window of the client.  As I watch the socket comminication on the
> console, I see that I have to move the mouse over the peer who needs to
> take the next step before anything will happen.  If I make a request
> from the other peer, it just sits there waiting for some response.  I
> have to actaully move over and give focus to the other window before it
> will respond.  I have to go back and forth like this until all
> communication is done.
>
> Any have any ideas on how this would be tied to the windows focus?
>
> --
> Posted viahttp://www.ruby-forum.com/.

Do you have explicit callbacks into Ruby to allow Ruby's green threads
to go? Ruby doesn't use operating system threads yet and QtRuby will
not be particularly respectful about letting Ruby run at appropriate
intervals. I'm guessing there are enough callbacks to Ruby code while
the window is in focus for your thread to run happily but the thread
is starved while the Qt window is receiving no external events. You
could fix this by creating a timer which periodically calls
Thread.pass and allows other Ruby threads to run.