class_docstr: This object implements a general K-way external merge sort for Python
  objects.
  
  >>> pool = MergePool()
  >>> # Add an unlimited number of items in any order
  >>> for item in my_items:
  ...     pool.add(item)
  ...
  >>> # Get the items back in sorted order
  >>> for item in pool.items():
  ...     print(item)
  
  This class uses the `marshal` module to write the items to temporary files,
  so you can only sort marshal-able types (generally: numbers, strings,
  tuples, lists, and dicts).
class_docstr_tok: ["This","object","implements","a","general","K-way","external","merge","sort","for","Python","objects",".",">",">",">","pool","=","MergePool","(",")",">",">",">","#","Add","an","unlimited","number","of","items","in","any","order",">",">",">","for","item","in","my_items",":","...","pool.add","(","item",")","...",">",">",">","#","Get","the","items","back","in","sorted","order",">",">",">","for","item","in","pool.items","(",")",":","...","print","(","item",")","This","class","uses","the","`","marshal","`","module","to","write","the","items","to","temporary","files",",","so","you","can","only","sort","marshal-able","types","(","generally",":","numbers",",","strings",",","tuples",",","lists",",","and","dicts",")","."]
code: def reduce_to(self, target, k):
      # Reduce the number of runs to "target" by merging "k" runs at a time
  
      if k < 2:
          raise ValueError("k=%s must be > 2" % k)
      if target < 1:
          raise ValueError("target=%s must be >= 1" % target)
      runs = self.runs
      while len(runs) > target:
          newpath, f = self._new_run()
          # Take k runs off the end of the run list
          tomerge = []
          while runs and len(tomerge) < k:
              tomerge.append(runs.pop())
          # Merge them into a new run and add it at the start of the list
          self._write_run(f, self._merge_runs(tomerge))
          runs.insert(0, newpath)
  
file_path: whoosh/src/whoosh/externalsort.py
imports: from __future__ import with_statement
  import os, tempfile
  from heapq import heapify, heappop, heapreplace
  from whoosh.compat import dump, load
label_desc: Use image node_id 12 for calling the SortingPool obj's underlying member method code with example usage: obj.reduce_to(target, k) without return types