# Buffer updates taking too long

**URL:** <https://www.ruby-forum.com/t/buffer-updates-taking-too-long/164081>\
**Category:** Ruby-Gnome 2\
**Created:** [March 27, 2009, 5:08pm UTC](https://www.ruby-forum.com/t/buffer-updates-taking-too-long/164081 "2009-03-27T17:08:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpflaum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@rpflaum](https://www.ruby-forum.com/u/rpflaum)\
**Post date:** [March 27, 2009, 5:08pm UTC](https://www.ruby-forum.com/t/buffer-updates-taking-too-long/164081/1 "2009-03-27T17:08:32Z")

</div>

I have searched around and I am not really finding an answer to what I  
need.

My program has 10-15 telnet session opened to a bunch of fibre channel  
switch command lines. The gui has an output buffer for each switch I  
have a valid connection to. Some of the commands I am running on the  
switch take considerable time to execute, and while doing so I am not  
getting any updates to my buffer that the user can see. What I am  
looking for is a why to give priority to the buffer update so the user  
knows their command took and is running in the background.

A very edited example follows:

functionbutton.signal\_connect(“clicked”) {  
puts “Portstatsshow button clicked”  
threadslist = []  
loop to run the following on every switch in the fabric  
threadslist \<\< Thread.new {  
$switchlist[switchname].portstatsshow  
}  
end  
threadslist.each { |aThread| aThread.join }  
}

The first line in the portstatsshow method is  
essentially:

```
buffer.insert.end_iter('this is going to take awhile')

```

I have tried the signal catch code for text\_insert and changed with no  
luck. I have tried writing and calling a method to place a mark at the  
end of the insert and scrolling that mark onscreen. Nothing helps. The  
entire portstatsshow method runs to completion before the buffer updates  
and shows the user the output. There has to be a way to force the update  
to happen when I insert the text and then proceed on with the rest of  
the method.

---

<div class="post-metadata">

**Author:** ![rpflaum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@rpflaum](https://www.ruby-forum.com/u/rpflaum)\
**Post date:** [March 27, 2009, 6:15pm UTC](https://www.ruby-forum.com/t/buffer-updates-taking-too-long/164081/2 "2009-03-27T18:15:59Z")

</div>

Disreguard the above. After even more digging I finally found the  
following little snippet of code that I stuck into my signal event:

while (Gtk.events\_pending?)  
Gtk.main\_iteration  
end

Everything is working as I expect now.

---

<div class="post-metadata">

**Author:** ![rpflaum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@rpflaum](https://www.ruby-forum.com/u/rpflaum)\
**Post date:** [March 28, 2009, 7:20pm UTC](https://www.ruby-forum.com/t/buffer-updates-taking-too-long/164081/3 "2009-03-28T19:20:10Z")

</div>

Rick Petrin wrote:

> Disreguard the above. After even more digging I finally found the  
> following little snippet of code that I stuck into my signal event:
> 
> while (Gtk.events\_pending?)  
> Gtk.main\_iteration  
> end
> 
> Everything is working as I expect now.

This forum is really nice - those snippets, and problems description  
often helped me with errors 🙂

---

<div class="post-metadata">

**Author:** ![rpflaum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@rpflaum](https://www.ruby-forum.com/u/rpflaum)\
**Post date:** [April 6, 2009, 7:03pm UTC](https://www.ruby-forum.com/t/buffer-updates-taking-too-long/164081/4 "2009-04-06T19:03:12Z")

</div>

Well I thought I had this beat, and in one case I did get it doing  
exactly what I wanted. However, I am still having an issue getting the  
GUI to stay updated when the program is running.

So I guess a bit more background

GTK has a main window. In that window are some button and a notebook  
section. The notebook section contains a tab for each telnet session I  
have open to a device. The tab contains a buffer and editor scrolled  
window. When the program is running there are long sessions where the  
buffer should just be updating the information I am seeing in the telnet  
session, and this mostly works. The issue is that I might have 15 of  
these telnet sessions open at one time each running in its own ruby  
thread issuing CLI commands and grabbing output. When things get hopping  
it can be 30 seconds between screen updates, and minutes for an update  
if I change tabs. Is there an easy way to make sure the main window (and  
thereby all the contained windows) cycles from all other threads that  
are running without having to rewrite the entire 6000+ (currently) lines  
of code to include yield statements for all the different threads?

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![rpflaum](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d2c977/32.png) [@rpflaum](https://www.ruby-forum.com/u/rpflaum)\
**Post date:** [April 19, 2009, 4:55pm UTC](https://www.ruby-forum.com/t/buffer-updates-taking-too-long/164081/5 "2009-04-19T16:55:23Z")

</div>

I’d start with using a profiler like ruby-prof to figure out where the  
slow downs are. Maybe try disassociating the widgets and buffers for  
not viewed tabs. Pay particular attention to the widgets event  
handlers, I was amazed with how often some are called (hint move as much  
processing (especially db calls) out of the handlers as you can get away  
with).

HTH,  
Roy
