code: def generate_files_distributed(generator,
                                 output_name,
                                 output_dir,
                                 num_shards=1,
                                 max_cases=None,
                                 task_id=0):
    
    assert task_id < num_shards
    output_filename = sharded_name(output_name, task_id, num_shards)
    output_file = os.path.join(output_dir, output_filename)
    tf.logging.info("Writing to file %s", output_file)
    writer = tf.python_io.TFRecordWriter(output_file)
  
    counter = 0
    for case in generator:
      if counter % 100000 == 0:
        tf.logging.info("Generating case %d for %s." % (counter, output_name))
      counter += 1
      if max_cases and counter > max_cases:
        break
      example = to_example(case)
      writer.write(example.SerializeToString())
  
    writer.close()
    return output_file
docs: generate_files but with a single writer writing to shard task_id.