python-shell和多处理程序不打印

问题描述 投票:0回答:1

我有问题。我使用nodejs的python-shell npm软件包,该软件包允许向python发送IPC消息,并以IPC形式读取python脚本的打印语句。

所以首先,我创建了一个可以正常工作的python脚本,该脚本接受stdin并打印到stdout。

然后,我实现了python-shell IPC,以向python脚本发送消息,并且一切正常。

问题开始于我在python脚本中创建一个进程(使用multiprocessing.Process,并将活动移植到那里。

[这里,我注意到新创建的进程的stdout没有通过python-shell收到!但是怎么可能呢?

进程stdout是否与运行它的脚本相同?

示例,可在previous post上找到与同一问题有关的可调试代码。

[请-任何线索都可能有所帮助。

python node.js ipc stdout python-multiprocessing
1个回答
0
投票

可能与我目前正在做的事情相同。您可以使用PythonShell。让我们看一个示例,您便可以理解。

var myPythonScriptPath = 'script.py';

// Use python shell
var PythonShell = require('python-shell');
var pyshell = new PythonShell(myPythonScriptPath);

pyshell.on('message', function (message) {
// received a message sent from the Python script (a simple "print" statement)
console.log(message);
});

// end the input stream and allow the process to exit
pyshell.end(function (err) {
if (err){
    throw err;
};

console.log('finished');
});

让我知道您是否还有问题。快乐的编码。

© www.soinside.com 2019 - 2024. All rights reserved.