Forums

Communication between a process and a subprocess

My web app starts a subprocess using Popen. I need to exchange data with this subprocess.

My current solution uses files and works fine but I am asked to explore other solutions.

  • Can I handle a socketserver in my subprocess that I could connect to from « outside » ? As far as I have tested, I can't bind to any address other than localhost.
  • Does the subprocess run on the same machine as the app that started it and can I use sockets (from localhost to localhost) to communicate between these 2.
  • If I use multiprocessing.Process instead of subprocess.Popen, will it be possible to use Queues for communication ?

Thank you.

To answer each of your points in order:

  • No, you can't do that. We don't route arbitrary ports to the web servers.
  • Yes. If you start a subprocess from a web app, it will run on the same machine as the web app itself. You might be able to use a socket created in the same way as the one on this page and then use it to communicate. For the purpose of Googling, that kind of socket is called a named socket and it's only usable from the machine where it was created.
  • Whether that works or not will depend quite heavily on how multiprocessing and its queues interact with the web server infrastructure. That puts it very much in the "try it and if it works, then it works" category.

OK, thanks a lot.