I have been working on a python project for sometime which has been structured in following manner:
We have a function like this:
def execute_cmd(cmd): (out, err) = subprocess.Popen(cmd).communicate() return (out, err)
and this function is used over and over to execute binaries of a third party library.
I did a little bit research and understood that we can connect to the third party library over sockets, and communicate by sending JSON payloads.
I am trying to understand which approach is better and why?
From what I understand, everytime we create a subprocess, underlying OS has to create a PCB for it, allocate resources and deallocate resources after completion. However, I see that it is really common practice in python programming to create subprocesses. This has left me completely confused.
Which approach is better and why?