简体   繁体   中英

python-shell and multiprocessing not printing

I have a problem. I use nodejs's python-shell npm package that allows sending IPC messages to python, and read the python script's print statements as IPC back.

So first I created a fully working python script that accepts stdin and prints to stdout.

Then I implemented the python-shell IPC to send a message to the python script and everything worked.

THE ISSUE began when I created a process in the python script (using multiprocessing.Process), and ported the activity there.

Here I noticed that the newly created processes' stdout isn't received via python-shell! but how is it possible?

Isn't the processes stdout the same as the script running it?

Example, debugable code can be found at the previous post regarding the same issue.

Please - any lead may help.

May be the same thing I am doing currently. You can use PythonShell. Lets see a example then you can understand.

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');
});

Lete me know if you still have problem. Happy coding.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM