Note that there are some explanatory texts on larger screens.

plurals
  1. PORuby Shoes and MySQL: GUI freezes, should I use threads?
    primarykey
    data
    text
    <p>I'm trying to learn Shoes and decided to make a simple GUI to run a SQL-script line-by-line.</p> <p>My problem is that in GUI pressing the button, which executes my function, freezes the GUI for the time it takes the function to execute the script. </p> <p>With long scripts this might take several minutes.</p> <p>Someone had a similar problem (<a href="http://www.stackoverflow.com/questions/958662/shoes-and-heavy-operation-in-separate-thread">http://www.stackoverflow.com/questions/958662/shoes-and-heavy-operation-in-separate-thread</a>) and the suggestion was just to put intensive stuff under a Thread: if I copy the math-code from previously mentioned thread and replace my mysql-code the GUI works without freezing, so that probably hints to a problem with how I'm using the mysql-adapter?</p> <p>Below is a simplified version of the code:</p> <p>problem.rb:</p> <hr> <pre><code># copy the mysql-gem if not in gem-folder already Shoes.setup do gem 'mysql' end require "mysql" # the function that does the mysql stuff def someFunction con = Mysql::real_connect("myserver", "user", "pass", "db") scriptFile = File.open("myfile.sql", "r") script = scriptFile.read scriptFile.close result = [] script.each_line do |line| result &lt;&lt; con.query(line) end return result end # the Shoes app with the Thread Shoes.app do stack do button "Execute someFunction" do Thread.start do result = someFunction para "Done!" end end end stack do button "Can't click me when GUI is frozen" do alert "GUI wasn't frozen?" end end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload