def items(self, maxfiles=128):
"""Returns a sorted list or iterator of the items in the pool.
:param maxfiles: maximum number of files to open at once.
"""
if maxfiles < 2:
raise ValueError("maxfiles=%s must be >= 2" % maxfiles)
if not self.runs:
# We never wrote a run to disk, so just sort the queue in memory
# and return that
return sorted(self.current)
# Write a new run with the leftover items in the queue
self.save()
# If we have more runs than allowed open files, merge some of the runs
if maxfiles < len(self.runs):
self.reduce_to(maxfiles, maxfiles)
# Take all the runs off the run list and merge them
runs = self.runs
self.runs = [] # Minor detail, makes this object reusable
return self._merge_runs(runs)
评论列表
文章目录