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.
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
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.
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?
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
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
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.