Sylvain Viart
9/30/2008 11:14:00 AM
Hi Brian,
Brian Candler a =C3=A9crit :
> Sylvain Viart wrote:
> =20
>> It seems that ruby have difficulties to catch exception in multi
>> threaded mode, any hint?
>> =20
>
> For debugging purposes, maybe you want Thread.abort_on_exception =3D tr=
ue=20
> (or just run ruby with -d flag)
> =20
Thanks good to know that.
> 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?=20
Sorry, I was late yesterday and my post is confusing.
In fact, I've made some tests and I suspect some strange behavior (or=20
unknown to me) on exception handling.
In the lib, we got a bloc with
484 rescue Exception =3D> e
Which I would expect to catch anything. but it missed Errno::EHOSTUNREACH=
=2E
I didn't find a good explanation so I suspect that exception in threads=20
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.rb=
506 rescue
507 puts "caught:#{$!}"
508 end
it works?? Why?
Why the normally more open "rescue Exception =3D> e" didn't do its job?
That's why I suspect some interaction between exception and threaded=20
execution.
It seems I missed something about exception or so. :-
> Is no warning generated for the non-existent host?
>
> =20
>> # execute commands on all servers
>> begin
>> session.exec( "hostname" )
>> rescue Exception =3D> e
>> p "main:#{e}"
>> end
>> =20
Sorry for that, I was expecting this bloc not using the begin/rescue in=20
fact.
The rescue here, catch the Errno::EHOSTUNREACH., not caught internally=20
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=
=20
> of the threads and return an array of them. I don't know if it does so.=
=20
> Perhaps you can use something like this:
>
> errs =3D []
> ...
> :on_error =3D> lambda { |server| errs << server }
> ...
> session.exec "hostname"
> unless errs.empty?
> puts "The command failed on #{errs.size} hosts"
> end
> =20
Hum, nice, I'm gonna try. :-)
Would it catch the Errno::EHOSTUNREACH?
Thanks for your hints.
Regards,
Sylvain.