Keep in mind that rails and fork don't get along very well. If you  
just plain fork like you wold in a normal ruby scrip[t you will get  
the Mysql has gone away error and your db connection will be borken.  
Here is a little hack that will let you get away with forking without  
losing your db connection in rails:



   fork do
     LongProcess.do_something(that_takes_a_long_time)
     Kernel.exec "echo -n"
   end

	That last Kernel.exec "echo -n" is the hack that will keep your db  
connection from "going away"


Cheers-
-Ezra


On Mar 8, 2006, at 3:20 PM, Marcus Andersson wrote:

> Do it in a thread seems like the simplest solution but I don't know  
> if it works in this setup with Rails and SCGI (Rails may be  
> performing clean up on resources that the thread uses when the  
> request returns while the thread is still running)
>
> I just want to be able to invoke the external script in an async  
> manner (passing along a parameter as well somehow) and also so that  
> it doesn't interfere with Rails way of doing threads (or not doing  
> threads...).
>
> Thanks for the answer.
>
> /Marcus
>
> Robert Klemme skrev:
>> 2006/3/8, Marcus Andersson <m-lists / bristav.se>:
>>> I have a long running process that I want to start from a Rails  
>>> request.
>>> But, because it takes so long to execute, I want to start it in a
>>> separate process and then return. What is the best way to do that?
>> You have several options - at leas these:
>>  - do it in a thread
>>  - create a new process using fork's block form, which executes the
>> block in the child
>>  - create a completely new process via a standard fork call
>> Which one is best depends on the problem you are trying to solve,  
>> # of
>> CPU's available, personal taste etc.
>> Kind regards
>> robert
>> --
>> Have a look: http://www.flickr.com/photos/fussel-foto/
>
>