In Python, how do I continuously communicate with running Node.js process?

(Apologies if this is somewhat vague as I'm just getting started with Python.)

I'm in the process of creating a SublimeText 2 intellisense plugin that communicates with a running command-line node server spawned from a Node.js script. The node application I would like to commnicate with can be found here: https://github.com/clausreinke/typescript-tools. (Please note that once the tss command has been called, it starts it's own subprocess command-line repl which needs to receive commands to execute. Getting commands to that command line is an entirely different question in itself, which I have yet to resolve.)

I can successfully "talk" to node via:

self.process = subprocess.Popen( self.args,
                stdin = subprocess.PIPE,
                stdout = subprocess.PIPE,
                stderr = subprocess.STDOUT)

self.result = self.process.communicate()[0]

which is invoked using

self.thread = NodeJS( args )
self.thread.start()
self.handle_thread( self.thread )

The issue is that once the node.js file is executed, it closes the pipe and exits the IO process. Subsequent calls to the process returns a

ValueError: I/O operation on closed file

My question is: How do I start up the node app, run it in the background, and then "pipe" commands continuously to it from Python?

I would like to

  1. Start the node.js server when the plugin loads and keep it running in the background
  2. Listen for key input which i then send to node (already working)
  3. Pipe the output from the running node process (after it's looked up the definition) back to python and then display the output, but NOT close the thread or the process

All of the steps are complete except for the continuous asynchronous back-and forth, which I can't seem to figure out.

Any help would be appreciated.

Create a Unix Domain socket or mailslot in Python, connect to it in Node.js, and use that as your communication channel.