From: Brian Candler Date: 2008-09-30T17:53:22+09:00 Subject: Re: exception in thread? Sylvain Viart wrote: > It seems that ruby have difficulties to catch exception in multi > threaded mode, any hint? For debugging purposes, maybe you want Thread.abort_on_exception = true (or just run ruby with -d flag) Other than that I don't understand your problem. What behaviour do you see when you run your test program? What behaviour do you expect? Is no warning generated for the non-existent host? > # execute commands on all servers > begin > session.exec( "hostname" ) > rescue Exception => e > p "main:#{e}" > end That rescue won't catch exceptions in other threads. Each thread of execution is responsible for catching its own exceptions. If it doesn't, then the thread just terminates (unless Thread.abort_on_exception is set) It *is* possible for one thread to raise an exception in another thread (Thread#raise), but this is extremely hairy asynchronous programming and I would strongly discourage it. It would seem reasonable for session.exec to collect the status of each of the threads and return an array of them. I don't know if it does so. Perhaps you can use something like this: errs = [] ... :on_error => lambda { |server| errs << server } ... session.exec "hostname" unless errs.empty? puts "The command failed on #{errs.size} hosts" end -- Posted via http://www.ruby-forum.com/.