Ruby-Thread and Gtk

Hi to all,

I did all my best and try to find out a way how to use Ruby with Gtk and
Threads.
I need an example, or a better explaining about how this things works.
I found something like that
“In Ruby/GTK, you should use Ruby-Thread instead of
Gdk::Threadshttp://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3AThreads.
It’s a well known issue what ruby thread doesn’t work well with
Native-Thread. Almost of all case, Ruby-Thread works well and you don’t
need
call these functions in Ruby.” in here:
http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gdk%3A%3AThreads
but, it still doesn’t work for me.

Here is my situation:

require ‘mysql’
require ‘libglade2’

(…other code…)

def my_method
@thread_login = Thread.new {
begin
my = Mysql.new(“host”, “user”, “user”, “db”)
rescue Exception => e
puts e.to_s
end
}
end

@btn_ok.signal_connect(“clicked”){
my_method
}

The problem is that when I’m pressing the button, even if the Thread is
launched, the GUI freeze until the exception is displayed.

Please, I need some help with that badly.

Thank you.


Best Regards,

Alin

Hi,

In [email protected]
“[ruby-gnome2-devel-en] Ruby-Thread and Gtk” on Fri, 10 Nov 2006
18:05:41 +0200,
“Alin P.” [email protected] wrote:

What about the following change:

def my_method
@thread_login = Thread.new {
begin
my = Mysql.new(“host”, “user”, “user”, “db”)
rescue Exception => e
puts e.to_s
end
}
end

def my_method
@thread_login = Gtk.idle_add do
begin
my = Mysql.new(“host”, “user”, “user”, “db”)
rescue Exception => e
puts e.to_s
end
end
end

@btn_ok.signal_connect(“clicked”){
my_method
}

Thanks,

kou


Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

Thanks a lot kou,

For your fast feedback, even one minor change is noticed, the GUI still
is
freezing until the exception or positive answer from mysql is returned.
Maybe this is the way, but used together with threads ?!

Once again, thanks, but I have to find other solution.

Alin.

On 11/11/06, Kouhei S. [email protected] wrote:

def my_method
@thread_login = Gtk.idle_add do
}
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642


ruby-gnome2-devel-en mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


Best Regards,

Alin

It looks like MySQL is blocking… Ruby uses Green Threads, that is -
cooperative ones. So if one thread calls a blocking call, all threads
have to wait for it. I find it hard to believe that MySQL actually is
blocking… could you try this with a non-GTK ruby application?

On 11/11/06, Alin P. [email protected] wrote:

What about the following change:

@btn_ok.signal_connect(“clicked”){
Using Tomcat but need to do more? Need to support web services, security?

Get stuff done quickly with pre-integrated technology to make your job


Protect your digital freedom and privacy, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm

Ohad L.


Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

Yes, I can try that and this is the result:

Script (the whole script, I think you can try it also):

#!/usr/bin/ruby

require ‘mysql’

$stdout.sync=true
$stderr.sync=true

class Login
def initialize
# ----------- The new Thread ----------
thread_login = Thread.new do
begin
dbh=Mysql.real_connect(“80.96.96.142”,
“alin”, “alin”, “alin”)
puts “Connection successfull”
rescue Exception => e
puts e.to_s
end
end
# ----- The end of the thread --------

            # ---- One short iteration with sleep period of 1 sec

            10.times do
                    print "."
                    sleep 1
            end
            # ---------- End of iteration ----------------
    end

end
login=Login.new

I think that thread should be launched and no matter how long the
connection
will take in order to complete, the dots will be displayed in no time.
But the dots are not displayed, until the connection will have a
feedback.

Of course, I tried without the sleep also, and the same thing is
happening.

What seems to be the problem ?

PS: sorry for the comments, but I wanted to be sure that you understand
what
I’m trying to do :slight_smile:

On 11/11/06, Ohad L. [email protected] wrote:

is

Hi,

@thread_login = Thread.new {
begin

Get stuff done quickly with pre-integrated technology to make your job

Using Tomcat but need to do more? Need to support web services,
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


Best Regards,

Alin

Thanks a lot,

It’s a real real help.

Best regards,

Alin.

On 11/11/06, Ohad L. [email protected] wrote:

                    begin

I think that thread should be launched and no matter how long the
PS: sorry for the comments, but I wanted to be sure that you understand

Once again, thanks, but I have to find other solution.
[email protected]>

  rescue Exception => e
   puts e.to_s


easier
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


Get stuff done quickly with pre-integrated technology to make your job

Using Tomcat but need to do more? Need to support web services,
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


Best Regards,

Alin

Networking calls are probably blocking. A quick google search seems to
show that this is a known issue… :frowning:

On 11/11/06, Alin P. [email protected] wrote:

$stderr.sync=true
puts e.to_s
# ---------- End of iteration ----------------

have to wait for it. I find it hard to believe that MySQL actually is

Once again, thanks, but I have to find other solution.
[email protected]>

  rescue Exception => e
   puts e.to_s


Geronimo

security?

Ohad L.
ruby-gnome2-devel-en mailing list
Alin
[email protected]
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


Protect your digital freedom and privacy, eliminate DRM, learn more at
http://www.defectivebydesign.org/what_is_drm

Ohad L.


Using Tomcat but need to do more? Need to support web services,
security?
Get stuff done quickly with pre-integrated technology to make your job
easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache
Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs