code: def write(self, data):
      
      ctx = context.get()
      if len(data) != 2:
        logging.error("Got bad tuple of length %d (2-tuple expected): %s",
                      len(data), data)
  
      try:
        key = str(data[0])
        value = str(data[1])
      except TypeError:
        logging.error("Expecting a tuple, but got %s: %s",
                      data.__class__.__name__, data)
  
      file_index = key.__hash__() % len(self._filehandles)
  
      # Work-around: Since we don't have access to the context in the to_json()
      # function, but we need to flush each pool before we serialize the
      # filehandle, we rely on a member variable instead of using context for
      # pool management.
      pool = self._pools[file_index]
      if pool is None:
        filehandle = self._filehandles[file_index]
        pool = output_writers.GCSRecordsPool(filehandle=filehandle, ctx=ctx)
        self._pools[file_index] = pool
  
      proto = kv_pb.KeyValue()
      proto.set_key(key)
      proto.set_value(value)
      pool.append(proto.Encode())
docs: Write data.
  
      Args:
        data: actual data yielded from handler. Type is writer-specific.