NodeJS派生的Python流程-Python的process.send()的替代方法?

联科

我正在用NodeJS派生一个Python脚本,并且在派生时,默认情况下,NodeJS在此新进程和父进程之间创建一个IPC。

使用NodeJS,可以将消息从孩子发送给父母 process.send({msg : 'toto'})

如何使用Python做到这一点?

http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

联科

好吧,我找到了,终于很容易了。这只是关于写正确的文件描述符。

在NodeJS端参数上,生成如下脚本:

var child = child_process.spawn('python', ['hello.py'], {
  stdio:[null, null, null, 'ipc']
});

child.on('message', function(message) {
  console.log('Received message...');
  console.log(message);
});

由于“ ipc”通道是第四个参数,因此您必须在filedescriptor 3上进行编写。在Python端:

import os

os.write(3, '{"dt" : "This is a test"}\n', "utf8")

完毕。您将在child.on('message'回调。

干杯!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python超级方法和调用替代方法

当您希望创建派生的Singleton时,使用Python模块的替代方法

python / flask的Golang替代品send_from_directory()

Python-time.sleep的替代方法

python中嵌套for循环的替代方法

python CNTK中损失函数的替代方法

Python 2.7之前的dict理解的替代方法

Python,Django:原始SQL查询的替代方法

Python:更改函数或替代方法的循环if语句

Python是质数列表的更快替代方法?

python中list.extend的替代方法/更快的方法?

Java中python的dir()的替代方法是什么?

有没有替代python中重复if语句的方法

Python中所有格量词的替代方法

python中字符串格式的替代方法是什么

python解释器中“输入”键的替代方法?

具有重复值的python Enum的替代方法

Python在列表理解内引发错误(或更好的替代方法)

有什么比Python的http.server(或SimpleHTTPServer)更快的替代方法?

python 3中execfile的替代方法是什么?

在python中实现观察者模式的替代方法

有没有比Python的strftime更快的替代方法?

尝试在 Python 中持久化环境变量的替代方法

在Python中使用numpy.random.choice的更快替代方法?

硒替代python?访问Web元素的最快方法

python中SAS格式的替代方法是什么?

在 Python 中枚举函数有哪些替代方法?

在 python 2.7 中创建数组的替代/更快的方法

在 python 中编写 15 个 if else 语句的替代方法