0

I have created a grpc python client with round robin load-balancing policy

self.channel = grpc.insecure_channel(self.host,options=[("grpc.lb_policy_name", 
                                                         "round_robin")])

Passed first parameter as host and second parameter as a load-balancing policy.

self.blocking_stub = dict_pb2_grpc.ExampleServiceStub(self.channel)

passed channel to the stub as well.

self.executor = concurrent.futures.ThreadPoolExecutor(
        max_workers=self.thread_pool_size
    )

I am clear till this point the next step is I want to pass executor with custom number of threads. How can I pass executor to grpc.insecure_channel?

I have gone through (something?), but didn't find anything related to this.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

I saw your post on grpc-io group as well: https://groups.google.com/g/grpc-io/c/uwCRAx1SJFA. This question is slightly different.

How can I pass executor to grpc.insecure_channel?

gRPC client doesn't accept executor as an input. gRPC channels are thread-safe. You can use the same channel to invoke RPC on multiple threads.

For example, you can structure your code like:

stub = ...
executor = concurrent.futures.ThreadPoolExecutor()

def work():
  response = stub.Greet(...)
  handle_response(response)

for _ in range(100):
  executor.submit(work)
Lidi Zheng
  • 1,801
  • 8
  • 13