# Best way of dealing with progressbars

**URL:** <https://www.ruby-forum.com/t/best-way-of-dealing-with-progressbars/213209>\
**Category:** Ruby-Gnome 2\
**Created:** [October 26, 2011, 3:42pm UTC](https://www.ruby-forum.com/t/best-way-of-dealing-with-progressbars/213209 "2011-10-26T15:42:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [October 26, 2011, 3:42pm UTC](https://www.ruby-forum.com/t/best-way-of-dealing-with-progressbars/213209/1 "2011-10-26T15:42:39Z")

</div>

Hi!

What’s the best way of dealing with progressbars? I am currently  
using a Gtk.idle\_add function for updating a progressbar from a  
different thread. It doesn’t run very well. I was wondering if  
anyone has a better solution to this.

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [October 26, 2011, 4:18pm UTC](https://www.ruby-forum.com/t/best-way-of-dealing-with-progressbars/213209/2 "2011-10-26T16:18:22Z")

</div>

Nikolai W. wrote in post #1028602:

> Hi!
> 
> What’s the best way of dealing with progressbars? I am currently  
> using a Gtk.idle\_add function for updating a progressbar from a  
> different thread. It doesn’t run very well. I was wondering if  
> anyone has a better solution to this.

AFAIK, it’s the best way.

Do you have an example to take a look at ?

Simon

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [October 27, 2011, 10:00am UTC](https://www.ruby-forum.com/t/best-way-of-dealing-with-progressbars/213209/3 "2011-10-27T10:00:25Z")

</div>

On Wed, Oct 26, 2011 at 16:18, Simon A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Nikolai W. wrote in post #1028602:

> > What’s the best way of dealing with progressbars? I am currently  
> > using a Gtk.idle\_add function for updating a progressbar from a  
> > different thread. It doesn’t run very well. I was wondering if  
> > anyone has a better solution to this.

> AFAIK, it’s the best way.
> 
> Do you have an example to take a look at ?

No, not really. It’s an internal thing. My problem is that the  
progress tends not to be reported very well. Oh, well, fuck it.

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [October 27, 2011, 12:24pm UTC](https://www.ruby-forum.com/t/best-way-of-dealing-with-progressbars/213209/4 "2011-10-27T12:24:39Z")

</div>

On 26 October 2011 14:41, Nikolai W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi!
> 
> What’s the best way of dealing with progressbars? I am currently  
> using a Gtk.idle\_add function for updating a progressbar from a  
> different thread. It doesn’t run very well. I was wondering if  
> anyone has a better solution to this.

I tend to prefer either a timeout in the main thread that polls, or an  
IO source that listens for events (either via a pipe or socket from an  
external process). It makes it easier to throttle progress events if  
there are too many & helps maintain a separation between the  
processing code and UI implementation.

(But I also generally prefer to do all my heavy lifting in helper  
scripts, rather than the GUI)

## When you say it doesn’t run well, do you mean that the process is generally unresponsive or that there’s a lag between the progressbar update being scheduled and being drawn?

Random Musing - [http://www.frafferz.com/](http://www.frafferz.com/)  
Geek Blog - [http://geoffyoungs.github.com/](http://geoffyoungs.github.com/)

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [October 27, 2011, 11:29am UTC](https://www.ruby-forum.com/t/best-way-of-dealing-with-progressbars/213209/5 "2011-10-27T11:29:33Z")

</div>

On Thu, Oct 27, 2011 at 11:22, Simon A.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Nikolai W. wrote in post #1028759:
> 
> > No, not really. It’s an internal thing. My problem is that the  
> > progress tends not to be reported very well. Oh, well, fuck it.
> 
> I tested the attached program on 1.8.7 and 1.9.2, and it works without  
> problem.
> 
> Do you call external commands in your thread ?

I don’t mean that it doesn’t work, I just mean that it’s slow. The  
progress being monitored is mostly other Ruby code, that is slightly  
computation intense, but also COM activity through WIN32OLE.

---

<div class="post-metadata">

**Author:** ![Nikolai\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/df705f/32.png) [@Nikolai\_W](https://www.ruby-forum.com/u/Nikolai_W)\
**Post date:** [October 27, 2011, 11:22am UTC](https://www.ruby-forum.com/t/best-way-of-dealing-with-progressbars/213209/6 "2011-10-27T11:22:14Z")

</div>

Nikolai W. wrote in post #1028759:

> No, not really. It’s an internal thing. My problem is that the  
> progress tends not to be reported very well. Oh, well, fuck it.

I tested the attached program on 1.8.7 and 1.9.2, and it works without  
problem.

Do you call external commands in your thread ?

Simon
