You can use additional arguments to the map function, these arguments should be iterators, 1 element from each iterator will be passed to each iteration your job pool goes through:
def my_function(file, sorting_bool):
if sorting_bool:
# do this with `file`
else:
# do that with `file`
total = len(directory)
sorter = lambda x: x < 0.9 * total
dir_sorted = map(sorter, range(total))
pool.map(my_function, directory, dir_sorted)
In general for other tasks you could send a job id and total id to your job:
def my_function(file, job_id, total_jobs):
if job_id < total_jobs * 0.9:
# Do this
else:
# Do that
total = len(directory)
pool.map(my_function, directory, range(total), lambda: total)
And then use those numbers however you'd like inside of your my_function
If you have an unknown number of total jobs you could still create a generator to create a counter:
def counter():
i = 0
while True:
yield i
i += 1
pool.map(my_function, counter(), other, args)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…