# Threading issues

**URL:** <https://www.ruby-forum.com/t/threading-issues/182567>\
**Category:** Ruby-Gnome 2\
**Created:** [January 29, 2010, 11:54pm UTC](https://www.ruby-forum.com/t/threading-issues/182567 "2010-01-29T23:54:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dismal\_denizen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@dismal\_denizen](https://www.ruby-forum.com/u/dismal_denizen)\
**Post date:** [January 29, 2010, 11:54pm UTC](https://www.ruby-forum.com/t/threading-issues/182567/1 "2010-01-29T23:54:12Z")

</div>

Hello everyone,

I am aware that there are many people who have asked questions relating  
to multi-threaded Gtk applications. However, after much trawling through  
the Internet I still can’t work out why the following simple code will  
not produce any output:

require ‘gtk2’

Thread.new do  
sleep 1 # Look busy  
exit # Finished, exit  
end

# Main loop

loop do

# Process all currently pending events

Gtk.main\_iteration while Gtk.events\_pending?  
print ‘.’  
end

It seems as if the sleeping thread is causing events to be fired,  
because Gtk.events\_pending? remains true the whole time. This doesn’t  
sound right, but I can’t think of a better explanation for the code’s  
behaviour. The problem is that the UI will freeze while the other thread  
is running (I found this out whilst using Gtk.main, but a custom loop  
displays the issue more clearly).

My Gtk wizardry is quite limited, so I would appreciate any help 🙂

Thanks,  
Aiden

---

<div class="post-metadata">

**Author:** ![dismal\_denizen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@dismal\_denizen](https://www.ruby-forum.com/u/dismal_denizen)\
**Post date:** [January 30, 2010, 12:32am UTC](https://www.ruby-forum.com/t/threading-issues/182567/2 "2010-01-30T00:32:16Z")

</div>

Le vendredi 29 janvier 2010 à 23:54 +0100, Aiden Nibali a écrit :

> sleep 1 # Look busy  
> exit # Finished, exit  
> end
> 
> # Main loop
> 
> loop do
> 
> # Process all currently pending events
> 
> Gtk.main\_iteration while Gtk.events\_pending?  
> print ‘.’  
> end

It produces plenty of output here (fills my screen with dots immediatly)

---

<div class="post-metadata">

**Author:** ![dismal\_denizen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@dismal\_denizen](https://www.ruby-forum.com/u/dismal_denizen)\
**Post date:** [January 30, 2010, 1:25am UTC](https://www.ruby-forum.com/t/threading-issues/182567/3 "2010-01-30T01:25:06Z")

</div>

Pascal T. wrote:

> It produces plenty of output here (fills my screen with dots immediatly)

That’s very strange. What is your environment like? I’m running Ruby  
1.8.7 on Ubuntu Karmic Koala (32-bit) with the Ruby Gtk bindings found  
in the repositories, and I get no output at all ☹

---

<div class="post-metadata">

**Author:** ![dismal\_denizen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@dismal\_denizen](https://www.ruby-forum.com/u/dismal_denizen)\
**Post date:** [January 30, 2010, 10:56pm UTC](https://www.ruby-forum.com/t/threading-issues/182567/4 "2010-01-30T22:56:03Z")

</div>

Pascal T. wrote:

> See  
> [http://sourceforge.net/mailarchive/forum.php?thread\_name=dc3bf8581001120746kb5da118udd0a74439cc4dcd9%40mail.gmail.com&forum\_name=ruby-gnome2-devel-en](http://sourceforge.net/mailarchive/forum.php?thread_name=dc3bf8581001120746kb5da118udd0a74439cc4dcd9%40mail.gmail.com&forum_name=ruby-gnome2-devel-en)  
> then, and teport it to launchpad to get the fix in Ubuntu

Thanks for the pointer. I have installed the latest version of ruby-gtk2  
now and it works perfectly, filling my screen with glorious dots. I have  
reported the bug at  
[https://bugs.launchpad.net/ubuntu/+source/ruby-gnome2/+bug/514899](https://bugs.launchpad.net/ubuntu/+source/ruby-gnome2/+bug/514899).

---

<div class="post-metadata">

**Author:** ![dismal\_denizen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@dismal\_denizen](https://www.ruby-forum.com/u/dismal_denizen)\
**Post date:** [January 30, 2010, 9:02pm UTC](https://www.ruby-forum.com/t/threading-issues/182567/5 "2010-01-30T21:02:54Z")

</div>

Le samedi 30 janvier 2010 à 01:25 +0100, Aiden Nibali a écrit :

> Pascal T. wrote:
> 
> > It produces plenty of output here (fills my screen with dots immediatly)
> 
> That’s very strange. What is your environment like? I’m running Ruby  
> 1.8.7 on Ubuntu Karmic Koala (32-bit) with the Ruby Gtk bindings found  
> in the repositories, and I get no output at all ☹

See

> **[Thread: \[ruby-gnome2-devel-en\] ruby-gnome2 not fully functional (at...](https://sourceforge.net/p/ruby-gnome2/mailman/ruby-gnome2-devel-en/thread/dc3bf8581001120746kb5da118udd0a74439cc4dcd9@mail.gmail.com/)**

then, and teport it to launchpad to get the fix in Ubuntu

---

<div class="post-metadata">

**Author:** ![dismal\_denizen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@dismal\_denizen](https://www.ruby-forum.com/u/dismal_denizen)\
**Post date:** [January 31, 2010, 7:08pm UTC](https://www.ruby-forum.com/t/threading-issues/182567/6 "2010-01-31T19:08:23Z")

</div>

> Thanks for the pointer. I have installed the latest version of ruby-gtk2  
> now and it works perfectly, filling my screen with glorious dots. I have

Can you tell me how did you do that? Unless you’ve done it manually,  
I’m interested in instructions for other users..

–  
Guillaume C. - [NVC Communication Obstacles Game](http://zarb.org/~gc/)

---

<div class="post-metadata">

**Author:** ![dismal\_denizen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e19adc/32.png) [@dismal\_denizen](https://www.ruby-forum.com/u/dismal_denizen)\
**Post date:** [February 1, 2010, 6:29am UTC](https://www.ruby-forum.com/t/threading-issues/182567/7 "2010-02-01T06:29:05Z")

</div>

> Can you tell me how did you do that? Unless you’ve done it manually,  
> I’m interested in instructions for other users..

Unfortunately I had to build ruby-gtk2 0.19.3 from source. However, it  
looks as if the problem will be solved in Ubuntu 10.4, as this is the  
version which will be used for that release 🙂
