I am utilizing multiprocessing using imap, since I need the results in order of the tasks/jobs executed. I just realized that I need a different function for the first task/job. Is there a way to specify 2 functions for the imap (where the first function (say func1) is only applied to the first task/job, and the rest will execute the second function (say func2)?
What I currently have is like:
from multiprocessing import Pool
pools = 2
with Pool(pools) as p:
for result in p.imap(func2, args): # where args is an iterator/list of params to be passed to func2
# some more processing here on the result
Which basically before I realized what I needed to do.
Is there a way to do what I am looking for with imap? Or would I just have to execute func1 first, then do the imap with the second function. That would work, but I really wanted the first task and the second task to run in parallel (when pools is set to 2 at least).
Assume there are hundreds of tasks/jobs to be performed.