1

I have a list of lists I want to fill with pool results. My code is currently incorrect due to the callback syntax:

finalData = [[],[],[]]

pool = mp.Pool()
pool.apply_async(findData, args=(x), callback= for i,val in enumerate(result): finalData[i].append(val) )
pool.close()
pool.join()

The results from findData are in the format:

results = [[1],[2],[3]]

Why can't I use the for loop inline as a callback to get these desired results:

finalData = [[1],[2],[3]]

I'm trying to avoid writing a callback function using finalData as a global variable.

WxPilot
  • 133
  • 1
  • 8
  • May I ask why? The callback function actually seems most appropriate – Liviu Chircu Jun 23 '17 at 15:33
  • It doesn't work because it's not a function... Now, you may create a `lambda` but that would be pushing it... Just handle your returns on your own instead of waiting for a callback - you can see an example using `apply_async()` in [this answer](https://stackoverflow.com/a/44502827/7553525). – zwer Jun 23 '17 at 15:36

0 Answers0