class_docstr: Take a TSV file, split into N pieces (by byte location) and return
  an iterator on one of the pieces.  The pieces are equal by byte size,
  not by number of rows.  Thus, care needs to be taken when using this
  for distributed training, otherwise number of batches for different
  workers might be different.
class_docstr_tok: ["Take","a","TSV","file",",","split","into","N","pieces","(","by","byte","location",")","and","return","an","iterator","on","one","of","the","pieces",".","The","pieces","are","equal","by","byte","size",",","not","by","number","of","rows",".","Thus",",","care","needs","to","be","taken","when","using","this","for","distributed","training",",","otherwise","number","of","batches","for","different","workers","might","be","different","."]
code: def __iter__(self):
      # (self.begin, self.end) are the pointers to the begin and end
      # of file segment
      self.file.seek(0, 2)
      end = self.file.tell()
      self.begin = self.block_id * end / self.num_blocks
      self.end = (self.block_id + 1) * end / self.num_blocks
      self.file.seek(self.begin, 0)
      # make sure we're at the beginning of a full row
      if self.begin:
          self.file.readline()
      reader = csv.DictReader(
          (
              line.replace("\0", "")
              for line in iter(self.file.readline, "")
          ),
          fieldnames=self.field_names,
          delimiter=self.delimiter,
          quoting=csv.QUOTE_MINIMAL if self.quoted else csv.QUOTE_NONE,
      )
      # iterate until we're at the end of segment
      for row in reader:
          if self.file.tell() > self.end:
              break
          if self.drop_incomplete_rows:
              if any(map(lambda v: v is None, row.values())):  # drop!
                  continue
          yield row
  
imports: import csv
  import logging
  import sys
  import threading
  from typing import Dict, List, Optional, Type
  from pytext.utils.path import get_absolute_path
  from .data_source import generator_property, RootDataSource, SafeFileWrapper, ShardedDataSource
  from .session import SessionDataSource
label_desc: Use image node_id 2 for calling the BlockShardedTSV obj's underlying member method code with example usage: obj.__iter__() without return types