Can I update session variable in a new thread?

Hi,

I have a controller code which does the following

t1= Thread.new {
#some code
session[:executing] = "done"
}

Then in one of the periodic update methods if I access the
session[:executing] it is not updated to "done". Is there a problem if I
try to update session variable in a different thread?

If this ends up setting the session after rails has closed out the
session (ie pushed it back into the db, or sent the cookie back to the
client) then this won't work.

Fred

Frederick Cheung wrote:

session[:executing] it is not updated to "done". Is there a problem if I
try to update session variable in a different thread?

If this ends up setting the session after rails has closed out the
session (ie pushed it back into the db, or sent the cookie back to the
client) then this won't work.

Fred

How do I know whether rails has closed out and pushed the cookie back to
client? If I add a join before exiting from the action something like
below

def execute
t1 = Thread.new { #code
                  session[:executing] ="done";
                }

t1.join
end

In the above case the session variable is updated. How would I get this
working if I want the session to be updated sometime later and still not
in that function?

Regards,
Sudhindra

Frederick Cheung wrote:

How do I know whether rails has closed out and pushed the cookie back to
client?

There's going to be a pretty narrow window after your action method
returns and before rails has got as far as session cleanup. I can't
think you'd gain anything by waiting for your thread to exit there
rather than in your action.

Fred