[英]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.) (很抱歉,因为我刚开始使用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. 我正在创建一个SublimeText 2 intellisense插件,该插件与从Node.js脚本生成的正在运行的命令行节点服务器进行通信。 The node application I would like to commnicate with can be found here: https://github.com/clausreinke/typescript-tools .
我想与之通信的节点应用程序可以在这里找到: 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.)
(请注意,一旦调用tss命令,它将启动它自己的子进程命令行repl,该repl需要接收要执行的命令。将命令传递到该命令行本身是一个完全不同的问题,我尚未解决。 )
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. 问题在于,一旦执行了node.js文件,它将关闭管道并退出IO进程。 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? 我的问题是:如何启动节点应用程序,在后台运行它,然后从Python连续“传递”命令给它?
I would like to 我想要
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. 任何帮助,将不胜感激。
在Python中创建一个Unix域套接字或邮槽,在Node.js中连接到它,并将其用作您的通信通道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.