Python multiprocessing - tracking the process of pool.map operation

前端 未结 3 1585
鱼传尺愫
鱼传尺愫 2020-12-01 11:24

I have a function which performs some simulation and returns an array in string format.

I want to run the simulation (the function) for varying input parameter value

3条回答
  •  情话喂你
    2020-12-01 11:55

    There is no "easy fix". map is all about hiding implementation details from you. And in this case you want details. That is, things become a little more complex, by definition. You need to change the communication paradigm. There are many ways to do so.

    One is: create a Queue for collecting your results, and let your workers put results into this queue. You can then, from within a monitoring thread or process, look at the queue, and consume the results as they are coming in. While consuming, you can analyze them, and generate log output. This might be the most general way to keep track of progress: you can respond to incoming results in any way, in real time.

    A more simple way might be to slightly modify your worker function, and generate log output in there. By carefully analyzing the log output with external tools (such as grep and wc), you can come up with very simple means of keeping track.

提交回复
热议问题