WaitForReady in python

763 views
Skip to first unread message

Julian Gold

unread,
Aug 18, 2017, 10:23:52 AM8/18/17
to grpc.io
I am working on an architecture with a single client and multiple servers. GRPC raises an exception if the client starts without a server present, so I tried modifying the HelloWorld sample to wait until a call succeeds:

  done = False
 
while not done:
     
try:
          response
= stub.SayHello(helloworld_pb2.HelloRequest(name='you'), timeout=1)
         
print("Greeter client received: " + response.message)
         
done = True
     
except:
         
print('Waiting for server connect...')
          time
.sleep(1)


Strangely, though this works, it takes quite a while to connect when the server is started after the client (about 10 seconds or more) before showing the result. A quick internet search shows there is a WaitForReady option in C#, but there doesn't seem to be an equivalent in Python? How else can I check if a connection is ready?


   

Ken Payson

unread,
Aug 18, 2017, 11:37:17 AM8/18/17
to Julian Gold, grpc.io
There are a few ways to track channel state in Python. If you only want to block until it is connected, try

grpc.channel_ready_future(channel).result()



--
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 grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
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/a2f41bce-007a-4adb-8032-1ea3af6c5100%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Julian Gold

unread,
Aug 18, 2017, 11:45:08 AM8/18/17
to grpc.io, julian.b...@gmail.com
Thanks Ken, that looks useful!


On Friday, 18 August 2017 16:37:17 UTC+1, Ken Payson wrote:
There are a few ways to track channel state in Python. If you only want to block until it is connected, try

grpc.channel_ready_future(channel).result()


On Fri, Aug 18, 2017 at 7:23 AM, Julian Gold <julian.b...@gmail.com> wrote:
I am working on an architecture with a single client and multiple servers. GRPC raises an exception if the client starts without a server present, so I tried modifying the HelloWorld sample to wait until a call succeeds:

  done = False
 
while not done:
     
try:
          response
= stub.SayHello(helloworld_pb2.HelloRequest(name='you'), timeout=1)
         
print("Greeter client received: " + response.message)
         
done = True
     
except:
         
print('Waiting for server connect...')
          time
.sleep(1)


Strangely, though this works, it takes quite a while to connect when the server is started after the client (about 10 seconds or more) before showing the result. A quick internet search shows there is a WaitForReady option in C#, but there doesn't seem to be an equivalent in Python? How else can I check if a connection is ready?


   

--
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 grpc-io+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages