On Mon, Jul 10, 2017 at 7:33 AM, <[email protected]> wrote:

> I write Python client code for gRPC based server application (written in
> C++) and need to handle open channel errors in some way. What is right way
> for it?
>

Probably to make use of the "channel connectivity subscription" methods.

At least, I need setup timeout for insecure_channel() method call for case
> I use unreachable target or target host failed. How can I do it?
>
> Right now if I use incorrect server I can successfully create channel and
> need to set timeout for every gRPC call and fail on first call. But I
> definitely do not want to proceed with any call attempt if server is not
> correct. Especially, my app is some kind of database and I think it is
> right way to handle server connection errors in Connection() constructor
> (in Python DB API 2.0 terms) not in Cursor methods where I work with actual
> gRPC calls.
>
> What is right policy to handle channel connection errors (including open
> channel errors/timeouts) in Python gRPC?
>
> In the docs https://grpc.io/grpc/python/grpc.html?highlight=insecure_
> channel#grpc.insecure_channel I see *options* parameter but I do not
> understand what they are. Which parameters can I pass? Can it be channel
> open timeout or something like this?
>

Take a look at the methods available on the grpc.Channel
<https://grpc.io/grpc/python/grpc.html#grpc.Channel> object returned to you
by grpc.insecure_channel
<https://grpc.io/grpc/python/grpc.html#grpc.insecure_channel> - you should
see subscribe <https://grpc.io/grpc/python/grpc.html#grpc.Channel.subscribe>
and unsubscribe
<https://grpc.io/grpc/python/grpc.html#grpc.Channel.unsubscribe> among
them. Those are the means by which to monitor the channel's connectivity
state. You can use them directly if you wish, but I suspect you'll be
happier writing code that uses grpc.channel_ready_future
<https://grpc.io/grpc/python/grpc.html#grpc.channel_ready_future> to create
a grpc.Future <https://grpc.io/grpc/python/grpc.html#grpc.Future> that
matures if and when the channel gets connected. I think your code might
look something like

my_channel = grpc.insecure_channel(<arguments>)
my_channel_ready_future = grpc.channel_ready_future(my_channel)
<do some other stuff>
try:
  my_channel_ready_future.result(timeout=_MY_TIMEOUT)
except grpc.FutureTimeoutError:
  <handle channel-did-not-connect>
else:
  <make use of connected channel>

.
-Nathaniel

-- 
You received this message because you are subscribed to the Google Groups 
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/grpc-io/CAEOYnAQKDX%3DnQVUC9QXNk6sxng%2Bo1BE7yw_VGWmC12L04f2NBw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to