##// END OF EJS Templates
worker: change partition strategy to every Nth element...
Gregory Szorc -
r28181:f8efc8a3 default
parent child Browse files
Show More
@@ -152,14 +152,11 b" if os.name != 'nt':"
152 _exitstatus = _posixexitstatus
152 _exitstatus = _posixexitstatus
153
153
154 def partition(lst, nslices):
154 def partition(lst, nslices):
155 '''partition a list into N slices of equal size'''
155 '''partition a list into N slices of roughly equal size
156 n = len(lst)
156
157 chunk, slop = n / nslices, n % nslices
157 The current strategy takes every Nth element from the input. If
158 end = 0
158 we ever write workers that need to preserve grouping in input
159 for i in xrange(nslices):
159 we should consider allowing callers to specify a partition strategy.
160 start = end
160 '''
161 end = start + chunk
161 for i in range(nslices):
162 if slop:
162 yield lst[i::nslices]
163 end += 1
164 slop -= 1
165 yield lst[start:end]
General Comments 0
You need to be logged in to leave comments. Login now