title: Checking to see when a gRPC stream is empty or isn't streaming data
body: <p>I am creating a stub that connects to a server that streams off data at a specific interval, then uploading it to a TSDB.  I have implemented batching to optimize the upload, but if the amount of data streamed off in one interval doesn't aline to the batch size some data will not be uploaded until the next interval, which I don't want.  Is there a way on a gRPC stub to check if the stream is empty?</p>
  
  <pre><code>class DialInClient(object):
      def __init__(self, host, port, timeout=100000000, user='root', password='lablab'):
          self._host = host
          self._port = port
          self._timeout = float(timeout)
          self._channel = None
          self._cisco_ems_stub = None
          self._connected = False
          self._metadata = [('username', user), ('password', password)]
  
      def subscribe(self, sub_id):
          sub_args = CreateSubsArgs(ReqId=1, encode=3, subidstr=sub_id)
          stream = self._cisco_ems_stub.CreateSubs(sub_args, timeout=self._timeout, metadata=self._metadata)
          for segment in stream:
              yield segment 
  
      def connect(self):
          self._channel = grpc.insecure_channel(':'.join([self._host,self._port]))
          try:
              grpc.channel_ready_future(self._channel).result(timeout=10)
              self._connected = True
          except grpc.FutureTimeoutError as e:
              raise DeviceFailedToConnect from e
          else:
              self._cisco_ems_stub = gRPCConfigOperStub(self._channel)
  </code></pre>
  
  <p>If I set a low timeout, the whole channel disconnects, I want to add some sort of timeout in the for loop for streaming to see if I don't get another segment in 1 second yield <code>None</code> to tell my other part that that is the end and to upload without a full batch size.</p>