Use multiprocessing as local IPC

I am considering using the Python multiprocessing package for messaging between local python programs.

This seems to be the correct way: IF:

  • Programs will always run locally on the same computer (and the same OS instance)
  • Program implementation will remain in Python
  • Speed ​​matters

Is this possible if python processes were executed independently by the user, i.e. others were not created?

How?
Documents seem to give examples only when one of them creates the other.

+4
source share
2 answers
+1
source

Programs will always run locally on one computer (and the same OS instance)

Multiprocessing allows remote concurrency .

Program implementation will remain in Python

Yes and no. You can transfer another command to a python function. This will work, for example:

from multiprocessing import Process import subprocess def f(name): subprocess.call(["ls", "-l"]) if __name__ == '__main__': p = Process(target=f, args=('bob',)) p.start() p.join() 

Speed ​​matters

It depends on a number of factors:

  • how much overhead will lead to coordination between processes?
  • How many cores does your processor have?
  • How much disk I / O is required for each process? Do they work on the same physical disk?
  • ...

Is this possible if python processes were executed independently by the user, i.e. others were not created?

I am not an expert on this issue, but once I implemented something similar, using files for data exchange [basically one process ", the output file was tracked as an input source by another, and vice versa].

NTN!

+1
source

Source: https://habr.com/ru/post/1385772/


All Articles