user1192422
user1192422

Reputation: 151

Keep order while using multiprocessing in Python

Please advise how can I keep order while using multiprocessing in Python. Both func and somefunc return lists. Thanks,

results = []

def callback(*args): results.append(*args)

def in_parallel(fn, func):
   print 'Process started on',time.strftime('%H:%M:%S')
   pool = mp.Pool(processes = 4)
   for num, i in enumerate(somefunc(fn)):
      pool.apply_async(func, args = (i,), callback = callback([num, callback]))
   pool.close()
   pool.join()

   return results

Upvotes: 2

Views: 872

Answers (1)

user1192422
user1192422

Reputation: 151

The problem has been solved with the following:

  r = pool.map_async(...)
  r.wait()

Upvotes: 1

Related Questions