# Thread problems

**URL:** <https://www.ruby-forum.com/t/thread-problems/101214>\
**Category:** Rails\
**Created:** [August 3, 2006, 4:34pm UTC](https://www.ruby-forum.com/t/thread-problems/101214 "2006-08-03T16:34:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rolando\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d9b06d/32.png) [@Rolando\_A](https://www.ruby-forum.com/u/Rolando_A)\
**Post date:** [August 3, 2006, 4:34pm UTC](https://www.ruby-forum.com/t/thread-problems/101214/1 "2006-08-03T16:34:12Z")

</div>

I have a really long series of queries (import from other database\*)  
that takes about 2 or 3 minutes. I wanted to spawn a thread and put the  
job there, but there seems to be some problems with active record and  
threads: (this is what I found after googling)

Thread.abort\_on\_exception = true  
=\> true  
100.times do  
Thread.new do  
Client.find(:first)  
end  
end

this throws an exception… So the question here: Is someone working on  
this? if the answer is no, I will give it a try, because I really need  
threads to be working on my app. If the answer is yes, who is working on  
this? can I help you?.

- the import is done this way: fetch some records using a webservice,  
check if the data is in my database, import the new records and delete  
the old ones. Due to requirements, this is the only way to do it.

regards,  
rolando.-

---

<div class="post-metadata">

**Author:** ![Rolando\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d9b06d/32.png) [@Rolando\_A](https://www.ruby-forum.com/u/Rolando_A)\
**Post date:** [August 4, 2006, 4:04am UTC](https://www.ruby-forum.com/t/thread-problems/101214/2 "2006-08-04T04:04:03Z")

</div>

On Aug 3, 2006, at 7:34 AM, Rolando A. wrote:

> ```
> Client.find(:first)
> 
> ```
> 
> - the import is done this way: fetch some records using a webservice,  
> check if the data is in my database, import the new records and delete  
> the old ones. Due to requirements, this is the only way to do it.
> 
> regards,  
> rolando.-

Rolando-

```
Don't do that ;) You will only run into problems trying to use

```

threads that way within your rails applications. While some of the  
parts of rails are sort of thread safe, the entire environment as a  
whole is not thread safe. So you will get the errors that you are  
currently getting. I wrote the BackgrounDRb[1] plugin for just this  
type of problem. You can put the long tasks in another process in a  
drb server and get status updates from within rails. Have a look and  
see what you think.

Cheers-  
-Ezra

[1] [http://backgroundrb.rubyforge.org](http://backgroundrb.rubyforge.org)

---

<div class="post-metadata">

**Author:** ![Rolando\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/d9b06d/32.png) [@Rolando\_A](https://www.ruby-forum.com/u/Rolando_A)\
**Post date:** [August 7, 2006, 12:56am UTC](https://www.ruby-forum.com/t/thread-problems/101214/3 "2006-08-07T00:56:31Z")

</div>

Ezra Z. wrote:

> Rolando-
> 
> Don’t do that 😉 You will only run into problems trying to use  
> threads that way within your rails applications. While some of the  
> parts of rails are sort of thread safe, the entire environment as a  
> whole is not thread safe. So you will get the errors that you are  
> currently getting. I wrote the BackgrounDRb[1] plugin for just this  
> type of problem. You can put the long tasks in another process in a  
> drb server and get status updates from within rails. Have a look and  
> see what you think.
> 
> Cheers-  
> -Ezra
> 
> [1] [http://backgroundrb.rubyforge.org](http://backgroundrb.rubyforge.org)

Thanks!  
your plugin seems to be just what I needs. I’ll give it a try.

regards,  
rolando.-
