From: Charles Oliver Nutter Date: 2008-07-01T21:55:30+09:00 Subject: Re: Problem with Ruby Multithreading Neha Gupta wrote: > Hello Guys, > > I am trying to use threads in my RoR app. > But unfortunately I came across a very strange issue. > I am unable to use "finders" within my thread to read data from my > database. > In addition to this, the Thread does not allow me to create any new > object inside the Thread. > > Eg: > > class TagsController < ApplicationController > > def some_method > > begin > Thread.new do > new_user = User.new > end > rescue > p $! > end > > end > > end Like others, I'm not sure what you're trying to accomplish, but any exception thrown by the code in that thread will never escape the thread, and so this rescue is mostly useless. What you're probably seeing is that the TagsController has been reloaded in development mode before your thread actually runs. Since your thread holds on to a reference to the original TagsController, you've got multiple versions of it active at once, which Rails is warning you about. Is your intention to hit the database asynchronously? You should probably know that ActiveRecord isn't the most thread-safe thing in the world yet, so you're probably going to run into trouble. - Charlie