title: Python GRPC How to reuse channel correctly
body: <p>I am writing a GRPC python client to communicate with a GRPC server as below.</p>
  <pre><code>class GrpcClient:
      &quot;&quot;&quot;
      Class to send request to Grpc server.
      &quot;&quot;&quot;
  
      def __init__(self, host: str, port: int):
          self._server_address = host + ':' + str(port)
          with grpc.insecure_channel(self._server_address) as channel:
              self._stub = MyServerStub(channel)
  
      def invoke_method(self, request):
          response = self._stub.process(request)
          logging.info(&quot;response received: &quot; + str(response))
  
  </code></pre>
  <p>This result in error <strong>ValueError: Cannot invoke RPC on closed channel!</strong> since the channel was getting closed on <strong>int</strong> I modified as below</p>
  <pre><code>    def __init__(self, host: str, port: int):
          self._server_address = host + ':' + str(port)
          channel = grpc.insecure_channel(self._server_address)
          self._stub = MyServerStub(channel)
  </code></pre>
  <p>Now both the channel and stub gets reused but my worry is that the channel might not be closed which might lead into memory leak</p>
  <p>To prevent it I tried opening the channel and creating stub on each request which is expensive.</p>
  <p>Can anyone suggest a way of reusing channel and stub without any leak?</p>