# Multithreading

**URL:** <https://www.ruby-forum.com/t/multithreading/90872>\
**Category:** Rails\
**Created:** [April 2, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/multithreading/90872 "2007-04-02T17:27:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![masu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@masu](https://www.ruby-forum.com/u/masu)\
**Post date:** [April 2, 2007, 5:27pm UTC](https://www.ruby-forum.com/t/multithreading/90872/1 "2007-04-02T17:27:05Z")

</div>

hi

I do a lot of inserts (duration about 3 min) and would like to show a  
progressbar for the user during this inserts. I tried out to do it with  
threads, but without a success. Also forking a process doesn’t work  
(Windows XP). Somebody has an idea?

thanks in advance  
masu

example:

# this is my loading function

def load\_data  
Thread.new do  
load\_data\_into\_another\_db …  
end  
end

# this is a ajax function, which is called periodically

def ajax\_update\_progress\_bar  
Thread.new do  
render :text =\> Time.now.to\_s  
end  
end

---

<div class="post-metadata">

**Author:** ![masu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@masu](https://www.ruby-forum.com/u/masu)\
**Post date:** [April 2, 2007, 7:12pm UTC](https://www.ruby-forum.com/t/multithreading/90872/2 "2007-04-02T19:12:59Z")

</div>

On 4/2/07, masu [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> hi
> 
> I do a lot of inserts (duration about 3 min) and would like to show a  
> progressbar for the user during this inserts. I tried out to do it with  
> threads, but without a success. Also forking a process doesn’t work  
> (Windows XP). Somebody has an idea?

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

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![masu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@masu](https://www.ruby-forum.com/u/masu)\
**Post date:** [April 2, 2007, 7:28pm UTC](https://www.ruby-forum.com/t/multithreading/90872/3 "2007-04-02T19:28:01Z")

</div>

> I do a lot of inserts (duration about 3 min) and would like to show a  
> progressbar for the user during this inserts. I tried out to do it with threads, but without a success. Also forking a process doesn’t work (Windows XP). Somebody has an idea?

I had to do something similar recently. You can exec “start whatever” in  
windows and it will start a new process with the command line you  
provide (rake or ruby script/runner for example). The option /B will  
even hide the window for the new process.

Regarding to the communication back to the user, I did it by creating a  
“semaphore” file at launching time and deleting it at completion.  
Meanwhile I had a small ajax magic querying every n seconds back to the  
server and just checking if the semaphore was still alive. I was also  
showing a timestamp back to the users so they could know everything was  
peachy on the server side.

I know more solid solutions like Drb are available and recommended, but  
this one doesn’t need any installation/monitoring and it works fine for  
simple tasks.

regards,

javier ramirez

## –

Estamos de estreno… si necesitas llevar el control de tus gastos  
visita [http://www.gastosgem.com](http://www.gastosgem.com) !!Es gratis!!

---

<div class="post-metadata">

**Author:** ![masu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/fbc32d/32.png) [@masu](https://www.ruby-forum.com/u/masu)\
**Post date:** [April 3, 2007, 9:30am UTC](https://www.ruby-forum.com/t/multithreading/90872/4 "2007-04-03T09:30:31Z")

</div>

thanks for your replies. I’m going to try it out the exec thing.

by  
masu
