0

I used multiprocessing.Pool to imporove the performance of my Python server, when a task failed, I want to terminate it's child processes immediately.

I found that, if I create a process using Process, the terminate method can meets my needs, but if I create a process with Pool.apply_async, the return type is 'ApplyResult', and it can't terminate the corresponding process.

Is there any other way to do it?

lulijun
  • 415
  • 3
  • 22
  • The cleanest way is to use some shared variable that the subprocess will poll every now and then, and exit when set. – freakish Jan 13 '21 at 09:43
  • Do you look for this https://stackoverflow.com/questions/8533318/multiprocessing-pool-when-to-use-apply-apply-async-or-map? – mhhabib Jan 13 '21 at 09:43
  • @toRex Thank u, but what I actually want to know is how to terminate the process in Pool. It seems like we can't terminate the process in Pool, I guess the processes in Pool have the same lifetime with the Poll, they will take task and execute constantly. But I ran into a new problem, the multiprocessing.Pool doesn't work on Linux. https://stackoverflow.com/questions/65805160/the-different-performance-of-python-multiprocessing-pool-on-macos-and-linux-systHave you ever encountered the same problem? – lulijun Jan 20 '21 at 09:00
  • @freakish Thank u, it means we can only stop the task other than the process, right? Recently I ran into a new probleam, it seems like the multiprocessing.Pool doesn't work on Linux:https://stackoverflow.com/questions/65805160/the-different-performance-of-python-multiprocessing-pool-on-macos-and-linux-syst. Have you ever encountered the same problem? – lulijun Jan 20 '21 at 09:10

0 Answers0