0

Consider you want to launch in a loop several parallel processes in async way, and of course, get for each process its exit code and prints.

If we do something naive like:

i = 5
While i > 0:
    p = sp.Popen(["./my_module.py", "arg1", "arg2"], stdout=sp.PIPE, stderr=sp.PIPE)
    out, err = p.communicate()
    result = p.returncode
    i -= 1

This probably not work async because of communicate blocking method above.
Any ideas for the best simple way to achieve multiple processes allocation async way, and finally getting their results accumulated in list or something?

n0nvme
  • 1,248
  • 8
  • 18
JavaSa
  • 5,813
  • 16
  • 71
  • 121
  • Does this answer your question? [Non blocking subprocess.call](https://stackoverflow.com/questions/16071866/non-blocking-subprocess-call) – Thiago Barcala Oct 12 '20 at 18:13
  • @ThiagoBarcala: I havn't seen any concrete solution to accumulate results of several processes runs, in addition I prefer to avoid asyncio – JavaSa Oct 12 '20 at 18:30

1 Answers1

0

Try this project. It is an asynchronous multiprocessing implementation.

UPDATE: Also subprocess module from stdlib now supports asyncio, check the docs: https://docs.python.org/3/library/asyncio-subprocess.html

n0nvme
  • 1,248
  • 8
  • 18