# Again threading problems

**URL:** <https://www.ruby-forum.com/t/again-threading-problems/169155>\
**Category:** Ruby\
**Created:** [May 30, 2009, 12:08pm UTC](https://www.ruby-forum.com/t/again-threading-problems/169155 "2009-05-30T12:08:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [May 30, 2009, 12:08pm UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/1 "2009-05-30T12:08:37Z")

</div>

Hello.

I am now coding a small application that should do the following:

1. User inputs timestamps in a file.
2. Application starts a thread and check every second if the current  
time is equal to any timestamp in the file (stored in a struct however).
3. If its time, the thread call a function, a http post using mechanize.
4. Application should be runable both on linux and windows.

However, i have gotten some big problems, first, there were a bug with  
threads in ruby 1.8.6 and standard I/O (gets) + windows, however I got  
help here on the ruby forum to fix that with an alternative input  
method.

What the problem is now that the function i am calling in the thread  
doesn’t run anyway(some problem with mechanize and threads aswell?)  
since the function runs fine when i for example place it in initialize  
for the class. And I can comment out the function and for example just  
change a variable in it and it works fine aswell.

So I heard that in 1.9.1 there should be no bugs like this, however I  
haven’t yet found a way to fully install ruby 1.9.1(on windows) with  
mechanize (+ needs nokogiri), when trying to install them I always gets  
some kind of errors for missing .so files etc.

Anyone managed to install 1.9.1 + mechanize(+nokogiri)?  
Anyone had the same problem as me?  
What do people normally do when coding things like this?, I mean, the  
things that the application do shouldn’t be that unusual.

Best regards

---

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [May 30, 2009, 3:05pm UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/2 "2009-05-30T15:05:52Z")

</div>

> What the problem is now that the function i am calling in the thread  
> doesn’t run anyway(some problem with mechanize and threads aswell?)  
> since the function runs fine when i for example place it in initialize  
> for the class. And I can comment out the function and for example just  
> change a variable in it and it works fine aswell.

Setting Thread.abort\_on\_exception=true might help you

> Anyone managed to install 1.9.1 + mechanize(+nokogiri)?  
> Tried it once and [very quickly] gave up once I realized it had lots of  
> dependencies. I suppose you could install them using mingw…might be  
> hard, though. Cygwin might have a working shot at it. Another idea  
> might be virtualbox+linux or andlinux.  
> Cheers!  
> -=r

---

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [May 30, 2009, 6:29pm UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/3 "2009-05-30T18:29:34Z")

</div>

Thank you for answer.  
Yeah well, switching to linux would be the only option?  
Since according to this article(watch strike 3):  
[http://cbcg.net/2007/04/22/python-up-ruby-down-if-that-runtime-dont-work-then-its-bound-to-drizzown.html](http://cbcg.net/2007/04/22/python-up-ruby-down-if-that-runtime-dont-work-then-its-bound-to-drizzown.html)

MingW doesn’t work either according to this, this person seems to have  
kinda the same problem with ruby as I.

Only other option is to switch to linux?

---

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [May 30, 2009, 6:39pm UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/4 "2009-05-30T18:39:08Z")

</div>

So with other words, using linux in some way is the best alternative?

---

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [May 30, 2009, 7:39pm UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/5 "2009-05-30T19:39:22Z")

</div>

Hello There wrote:

> So with other words, using linux in some way is the best alternative?

If you get desperate enough 🙂  
-=r

---

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [May 30, 2009, 6:32pm UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/6 "2009-05-30T18:32:02Z")

</div>

Roger P. wrote:

> Another idea  
> might be virtualbox+linux or andlinux.

On the Windows platform, VMWare Server works well, and is free of  
charge.

The management interface will complain that it needs a server version,  
and on Win2K, you do have to start  
it manually. It also needs lots of RAM and CPU oomph.

I have run a Ubuntu desktop on an AMD 3500+ with 2GB, and it was nice  
to use. (Naturally you can’t play games or watch video on a guest).

Compared to my attempts at loading Linux, adding KVM and getting windows  
to run as a guest it was a dream!

Regards

Ian

---

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [May 31, 2009, 11:41am UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/7 "2009-05-31T11:41:42Z")

</div>

Just run JRuby. Install Java, unpack JRuby, done. Fast, real parallel  
threads.

---

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [May 31, 2009, 11:12am UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/8 "2009-05-31T11:12:13Z")

</div>

On 30.05.2009 18:39, Hello There wrote:

> So with other words, using linux in some way is the best alternative?

cygwin genereally works well and provides an environment which is pretty  
close to linux with the added benefit that you do not have to go through  
some form of Samba or VMWare configuration to make Windows folders  
accessible from a VM. My 0.02EUR…

Cheers

robert

---

<div class="post-metadata">

**Author:** ![hellothere1](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/a88e57/32.png) [@hellothere1](https://www.ruby-forum.com/u/hellothere1)\
**Post date:** [June 1, 2009, 11:02am UTC](https://www.ruby-forum.com/t/again-threading-problems/169155/9 "2009-06-01T11:02:44Z")

</div>

Hello There wrote:

> What the problem is now that the function i am calling in the thread  
> doesn’t run anyway(some problem with mechanize and threads aswell?)  
> since the function runs fine when i for example place it in initialize  
> for the class. And I can comment out the function and for example just  
> change a variable in it and it works fine aswell.

My advice is just to fix your program in 1.8.6 or 1.8.7. Threads work  
absolutely fine in 1.8, and as has been pointed out, you’re on your own  
if you have complex library dependencies with 1.9, as lots of 3rd-party  
libraries don’t work with 1.9.

As already advised, Thread.abort\_on\_exception = true should help you  
find out what’s going wrong in your thread. Or else you can add a bit of  
debugging yourself:

Thread.new do  
begin  
… normal stuff  
rescue Exception =\> e  
$stderr.puts “#{e}\n\t#{e.backtrace.join(”\n\t")}"  
end  
end
