I have program that does a bunch of file processing and the GUI froze up every time I ran it. I decided to do the trick of running my main code in a second thread and using the timer to update the gui every 100 ms. However, the problem is that the second thread that I run is working but very very slowly. Much slower than how it normally works. I have the timer: timer = Timer.new(self,ID_ANY) evt_timer(timer.id) {Thread.pass} timer.start(1000) my second thread: newthread = Thread.new do create_prompt_data create_groups create_xls end -- Posted via http://www.ruby-forum.com/.
That''s cause whenever you pass the thread to another Ruby thread, it takes time away from the main thread. And since your Processing code is in a Secondary Thread, it gets less time then the Main Thread. On Wed, Jul 7, 2010 at 6:42 PM, Chase Wilson <lists at ruby-forum.com> wrote:> I have program that does a bunch of file processing and the GUI froze up > every time I ran it. I decided to do the trick of running my main code > in a second thread and using the timer to update the gui every 100 ms. > However, the problem is that the second thread that I run is working but > very very slowly. Much slower than how it normally works. > > I have the timer: > timer = Timer.new(self,ID_ANY) > evt_timer(timer.id) {Thread.pass} > timer.start(1000) > > my second thread: > newthread = Thread.new do > create_prompt_data > create_groups > create_xls > end > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > wxruby-users mailing list > wxruby-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/wxruby-users >-- Mario Steele Lieutenant Commander 3 XO - Geo 99 XO - STO IFT Fleet Chief Engineer - Second Life http://www.trekfederation.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/wxruby-users/attachments/20100707/d44a6e62/attachment.html>
Mario Steele wrote:> That''s cause whenever you pass the thread to another Ruby thread, it > takes > time away from the main thread. And since your Processing code is in a > Secondary Thread, it gets less time then the Main Thread.No no, before I had created the second thread my computer would process the data and have a ton of CPU usage. Now with the thread it runs, but very very slowly and hardly any CPU usage. -- Posted via http://www.ruby-forum.com/.
On 07/07/2010 23:42, Chase Wilson wrote:> I have program that does a bunch of file processing and the GUI froze up > every time I ran it. I decided to do the trick of running my main code > in a second thread and using the timer to update the gui every 100 ms. >Is there any way you can break up the file processing into small discrete tasks? If so, you could could have a queue of jobs and consume them one at a time in an evt_idle loop. This is a more efficient (and simpler) way of keeping the GUI responsive whilst handling long-running tasks. Ruby 1.8 green threads + Wx::Timer has some overhead (thread context switching) and isn''t that efficient - it forces switching to the GUI thread when updates aren''t needed.> However, the problem is that the second thread that I run is working but > very very slowly. Much slower than how it normally works. > > I have the timer: > timer = Timer.new(self,ID_ANY) > evt_timer(timer.id) {Thread.pass} > timer.start(1000) >This is switching context every 1000ms - i.e. every second. Did you mean timer.start(10) or (simpler, if you don''t need later control) Timer.every(10) { Thread.pass } alex