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
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.
Mario S. 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.
On 07/07/2010 23:42, Chase W. 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