# Getting data back from thread spawn

**URL:** <https://www.ruby-forum.com/t/getting-data-back-from-thread-spawn/52663>\
**Category:** Rails\
**Created:** [January 17, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/getting-data-back-from-thread-spawn/52663 "2006-01-17T20:53:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PJ\_Hyett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@PJ\_Hyett](https://www.ruby-forum.com/u/PJ_Hyett)\
**Post date:** [January 17, 2006, 8:53pm UTC](https://www.ruby-forum.com/t/getting-data-back-from-thread-spawn/52663/1 "2006-01-17T20:53:04Z")

</div>

I have a script that needs to be run, that in some cases will take  
longer than the server timeout. So, I’m thinking just throw the script  
in its own thread, but I need to be able to get the data back from  
that thread and refresh the page with the data returned. Any  
suggestions how to do this?

Thanks,  
PJ

---

<div class="post-metadata">

**Author:** ![PJ\_Hyett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@PJ\_Hyett](https://www.ruby-forum.com/u/PJ_Hyett)\
**Post date:** [January 17, 2006, 8:59pm UTC](https://www.ruby-forum.com/t/getting-data-back-from-thread-spawn/52663/2 "2006-01-17T20:59:06Z")

</div>

This is a noob answer, but couldn’t you fetch the data asynchronously  
with  
the Rails AJAX methods? Or does that also encounter the server timeout  
limit?

If the server timeouts on AJAX calls, I think your only other option is  
to  
have the thread record its data somewhere (DB, flatfile, etc) and reload  
the  
page on regular intervals using a periodic\_call\_remote observer to see  
if  
the thread has made the data available yet…

-Will

---

<div class="post-metadata">

**Author:** ![PJ\_Hyett](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/e95f7d/32.png) [@PJ\_Hyett](https://www.ruby-forum.com/u/PJ_Hyett)\
**Post date:** [January 18, 2006, 10:08am UTC](https://www.ruby-forum.com/t/getting-data-back-from-thread-spawn/52663/3 "2006-01-18T10:08:49Z")

</div>

You could send back a static html page with a little animated “progress  
bar” gif and with  
the “refresh” header set to check back with the server every few  
seconds. If the server’s  
still not ready it just sends back the same “in progress” page… until  
it has the  
results. I think that’s how them fancy travel sites (like orbitz??) do  
it…

b
