code: def write_worker(q_out, fname, working_dir):
      
      pre_time = time.time()
      count = 0
      fname = os.path.basename(fname)
      fname_rec = os.path.splitext(fname)[0] + '.rec'
      fname_idx = os.path.splitext(fname)[0] + '.idx'
      record = mx.recordio.MXIndexedRecordIO(os.path.join(working_dir, fname_idx),
                                             os.path.join(working_dir, fname_rec), 'w')
      buf = {}
      more = True
      while more:
          deq = q_out.get()
          if deq is not None:
              i, s, item = deq
              buf[i] = (s, item)
          else:
              more = False
          while count in buf:
              s, item = buf[count]
              del buf[count]
              if s is not None:
                  record.write_idx(item[0], s)
  
              if count % 1000 == 0:
                  cur_time = time.time()
                  print('time:', cur_time - pre_time, ' count:', count)
                  pre_time = cur_time
              count += 1
docs: Function that will be spawned to fetch processed image
      from the output queue and write to the .rec file.
      Parameters
      ----------
      q_out: queue
      fname: string
      working_dir: string