From: "ara.t.howard" Date: 2008-07-16T01:18:45+09:00 Subject: Re: Handling exceptions in Threads On Jul 15, 2008, at 6:35 AM, Guillermo.Acilu@koiaka.com wrote: > > If I leave the Thread.abort_on_exception = false, the algorithm ends > after > triggering about 10 threads. If I set it to > Thread.abort_on_exception = > true, the algorithm end abnormally, but without printing any error > message. > > I have added the following code at the end of the method called by the > thread: > > rescue Exception => error > puts "#{error.class}: #{error.message}" > > But I cannot get any error message in the console. I am sure that the > problem is something related with the database, but I do not know > how to > solve the problem if I do not see the error message. > > Any ideas? 1) STDERR.puts message stdout bufferes and can get lost 2) it's *highly* unlikely the db handle is thread safe and, if it is, it'll be native thread safe not green thread safe. aka - you will not get anything from using MT to execute your queries. so, just use producer/consumer to both simplify and speed up your application. for example q = Queue.new queries = list_of_queries done = Object.new.freeze producer = Thread.new do Thread.current.abort_on_exception queries.each do |query| q.push db.execute(query) end q.push done end while( ( result = q.pop) != done ) handle_result result end you could handle the results in threads too using the same pattern. the key is here is simply to eliminate the MT aspect of the db handle usage - for sanity and correctness. cheers. a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama