Hi Brian,

Brian Candler a écrit :
> 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)
>   
Thanks good to know that.
> Other than that I don't understand your problem. What behaviour do you ee when you run your test program? What behaviour do you expect? 
Sorry, I was late yesterday and my post is confusing.

In fact, I've made some tests and I suspect some strange behavior (or 
unknown to me) on exception handling.
In the lib, we got a  bloc with

484       rescue Exception => e

Which I would expect to catch anything. but it missed Errno::EHOSTUNREACH.
I didn't find a good explanation so I suspect that exception in threads 
are behaving somewhat differently.

Strangely, if I add another rescue statement in the lib:

/var/lib/gems/1.8/gems/net-ssh-multi-1.0.0/lib/net/ssh/./multi/session.rb06  rescue
507      puts "caught:#{$!}"
508  end

it works?? Why?

Why the normally more open "rescue Exception => e" didn't do its job?
That's why I suspect some interaction between exception and threaded 
execution.
It seems I missed something about exception or so. :-\

> 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
>>     
Sorry for that, I was expecting this bloc not using the begin/rescue in 
fact.
The rescue here, catch the Errno::EHOSTUNREACH., not caught internally 
by the lib.

I should have written:

session.exec( "hostname" )

With no rescue, the program fail, no job is performed on any host.

> 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
>   
Hum, nice, I'm gonna try. :-)
Would it catch the Errno::EHOSTUNREACH?

Thanks for your hints.
Regards,
Sylvain.